在安装 firebase-tools 时,尽管已安装,NPM 仍继续发出依赖性警告

While installing firebase-tools, NPM kept on giving dependency warnings despite they have been installed

当我通过 运行 在我的函数文件夹中使用命令 sudo npm i -g firebase-tools 将我的 firebase-tools 从版本 8.6.0 升级到 8.7.0 时,我收到了这些警告:

npm WARN deprecated har-validator@5.1.5: this library is no longer supported
/.npm/bin/firebase -> /.npm/lib/node_modules/firebase-tools/lib/bin/firebase.js
npm WARN ws@7.3.1 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.3.1 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.

然后我尝试按要求安装依赖项。例如,对于 bufferutil。 我试过这两个安装命令:

sudo npm install --save-dev bufferutil@^4.0.1

sudo npm install bufferutil@^4.0.1

两者都安装成功并显示如下消息:

> bufferutil@4.0.1 install /_app/functions/node_modules/bufferutil
> node-gyp-build

npm notice save bufferutil is being moved from dependencies to devDependencies
+ bufferutil@4.0.1
updated 1 package in 7.06s

29 packages are looking for funding
  run `npm fund` for details

我也为 utf-8-validate@^5.0.2 做了同样的事情,它给出了同样的成功信息。

但是当我 运行 firebase deploy --only functions 它再次告诉我更新到 8.7.0 无论我 运行 在函数中安装命令 sudo npm i -g firebase-tools 多少次文件夹

╭───────────────────────────────────────────╮
│                                           │
│      Update available 8.6.0 → 8.7.0       │
│   Run npm i -g firebase-tools to update   │
│                                           │
╰───────────────────────────────────────────╯

所以我尝试再次安装这两个依赖项,但它给出了与第一个相同的消息,它需要 bufferutil@^4.0.1utf-8-validate@^5.0.2

我不确定我在这里错过了什么。虽然已经安装了,但似乎没有安装。

这是我的 package.json

{
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "scripts": {
    "serve": "firebase emulators:start --only functions",
    "shell": "firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "10"
  },
  "dependencies": {
    "firebase-admin": "^8.10.0",
    "firebase-functions": "^3.9.1",
    "pg": "^8.3.0"
  },
  "devDependencies": {
    "bufferutil": "^4.0.1",
    "firebase-functions-test": "^0.2.0",
    "utf-8-validate": "^5.0.2"
  },
  "private": true
}

终于找到问题了

显然问题的发生是因为我的计算机上安装了两个 firebase 可执行文件。 因此,我更新的 firebase 与执行的 firebase 不同(因为不同的路径和不同的 package.json)。

对我来说,这是因为我将 npm 设置为从中国镜像服务器安装 firebase 依赖项,这有很大帮助(然后我不需要 VPN 来安装 firebase 依赖项)。但是我忘记了两个 firebase 可执行文件。 Idk,但您可能会遇到由其他原因引起的相同问题。

所以我解决了这个问题:

  1. 找出两个 firebase 位置。就我而言,它是 /opt/local/bin 中的一个,/Users/ME/.npm/bin 中的另一个。所以你的位置可能和我的不一样。
  2. 我通过firebase --version检查了每个对应的目录,看看哪个目录有最新版本。
  3. 然后我删除了旧版本并将 PATH 添加到我的 .bash_profile 中正确的 firebase。所以我在 export PATH="/opt/local/bin"
  4. 之前添加了 export PATH="/Users/ME/.npm/bin"

然后重新启动终端或执行 source ~/.bash_profile 然后就成功了!!

希望这对某人有所帮助。