无法使用 npm 安装 firebase CLI

Cannot install firebase CLI with npm

当我尝试安装 firebase-tools 时:

npm install -g firebase-tools

我收到以下错误:

npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated mkdirp@0.5.4: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
/usr/local/bin/firebase -> /usr/local/lib/node_modules/firebase-tools/lib/bin/firebase.js
npm WARN lifecycle The node binary used for scripts is /snap/bin/node but npm is using /snap/node/2609/bin/node itself. Use the `--scripts-prepend-node-path` option to include the path for the node binary npm was executed with.

> protobufjs@6.8.9 postinstall /usr/local/lib/node_modules/firebase-tools/node_modules/protobufjs
> node scripts/postinstall

2020/03/31 16:23:53.220338 cmd_run.go:884: WARNING: cannot create user data directory: cannot create "/nonexistent/snap/node/2609": mkdir /nonexistent: permission denied
cannot create user data directory: /nonexistent/snap/node/2609: Permission denied
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/firebase-tools/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! protobufjs@6.8.9 postinstall: `node scripts/postinstall`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the protobufjs@6.8.9 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/david/.npm/_logs/2020-03-31T21_23_53_670Z-debug.log

我用谷歌搜索了这个错误,但没有找到任何相关内容。如何安装 firebase-tools?

我遇到了同样的问题,但我通过不在全局安装来修复它

试试这个 npm 安装 firebase-tools

sudo npm install -g firebase-tools

原因:您使用 snap 来安装节点,而 snap 不允许应用程序写入 /usr/local,这是安装所有全局包的地方。

如何解决这个问题?

  1. snap remove node - 卸载 node
  2. 的 snap 版本
  3. sudo apt-get install nodejs - 安装 nodejs
  4. npm install -g firebase-tools - 现在应该可以了