【问题标题】:While installing firebase-tools, NPM kept on giving dependency warnings despite they have been installed在安装 firebase-tools 时,尽管已经安装了 NPM,但仍然会发出依赖警告
【发布时间】:2020-08-17 11:28:28
【问题描述】:

当我通过在我的函数文件夹中运行命令 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 时,无论我在functions 文件夹中运行安装命令sudo npm i -g firebase-tools 多少次,它都会再次告诉我更新到8.7.0

╭───────────────────────────────────────────╮
│                                           │
│      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
}

【问题讨论】:

  • 你试过删除node_modules文件夹并执行npm install吗?
  • 它给了我npm ERR! code EINVALIDTYPE npm ERR! typeerror Error: Argument #5: Expected object but got string。然后我在删除它之前做了npm cache clean --force。然后我得到了npm WARN saveError ENOENT: no such file or directory, open '/usr/local/lib/package.json' npm WARN enoent ENOENT: no such file or directory, open '/usr/local/lib/package.json'

标签: firebase npm google-cloud-functions firebase-tools


【解决方案1】:

终于找到问题了。

很明显,问题的发生是因为我的计算机上安装了两个 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" 之前添加了export PATH="/Users/ME/.npm/bin"

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

希望这可以帮助某人。

【讨论】:

  • 谢谢。很有用。在我的 Windows 10 中。我发现 C:\Users\admin\AppData\Roaming\npm> ./firebase.cmd --version 为 9.1.0,并且 C:\Program Files\nodejs> ./firebase.cmd --版本为 9.10.0 因此,我需要删除我的 AppData\Roaming 文件夹中的那个。
猜你喜欢
  • 2023-01-10
  • 1970-01-01
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 2020-09-22
相关资源
最近更新 更多