通过 npm 安装 firebase 时遇到错误 | 在 附近解析时意外结束 JSON 输入

IT技术 reactjs firebase npm npm-install
2021-05-11 06:36:36

我正在尝试在我的新react项目中安装 firebase,但我无法安装它。

无论是错误还是 npm 都需要时间。我等了半个多小时。

在此处输入图片说明 在此处输入图片说明

2个回答

试试这个(您可能需要运行,sudo或者如果您使用的是 Windows,请cmd以管理员身份打开)。

npm cache clean --force

然后运行

npm install firebase

虽然上述答案似乎适用于大多数情况,但对我的情况却并非如此。我试过

npm cache clean -f
npm install firebase

没有运气!

我关注了这个线程,它解释了很多关于 npm 缓存的内容,也得出了上述方法应该可以工作的结论,也许只是在安装 firebase 之前验证缓存

   npm cache clean -f
   npm install firebase
   npm verify cache

不过,运气不好,所以我决定将它添加到 package.json 中作为此时最新稳定版本 firebase (8.0.0) 的依赖项。

所以转到 package.json 文件和依赖项部分

"dependencies": {
     "firebase": "^8.0.0",
     ...other dependencies
     }

并做

npm cache clean -f
npm install npm@latest

这应该适用于类似的情况,请查看此链接以了解 npm 上的缓存如何详细工作。