【问题标题】:NPM Install Error:Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'NPM 安装错误:在“...nt-webpack-plugin”附近解析时 JSON 输入意外结束:“0”
【发布时间】:2019-05-14 19:50:45
【问题描述】:

创建新的 Angular 5 项目时:

节点版本:8.9.2

npm 版本:5.5.1

我的命令是:

npm install -g @angular/cli

错误是:

npm ERR! **Unexpected end of JSON input while parsing near '...nt-webpack-plugin":"0'**
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Aashitec\AppData\Roaming\npm-cache\_logs\2017-12-06T13_10_10_729Z-debug.log

The error log is here

【问题讨论】:

  • "npm cache clean --force" 不带引号可能是您问题的答案。
  • 为我工作,说希望我知道自己在做什么。我没有。
  • sudo npm cache clean --force sudo npm cache verify sudo npm i npm@latest -g 这些命令对我有用
  • @tonix 谢谢兄弟,你的解决方案也对我有用,npm ERR!在“...lFicG0K5VKDuUbV0\n4AU”附近解析时 JSON 输入意外结束(npm install --save firebase-admin)
  • 这对我不起作用,我尝试了多次,如果我下次清理缓存,我会收到类似 npm ERR 的错误! sha512-I4kM....

标签: node.js angular npm npm-install


【解决方案1】:

在我的情况下,我将网络更改为更强大的网络,npm 安装完美:

npm cache clean --force

【讨论】:

    【解决方案2】:

    很简单

    npm cache clean --force
    

    然后通过

    安装节点依赖
    npm install
    

    【讨论】:

    • 请务必在提供新答案之前查看现有答案。在这种情况下,有 30 多个答案,其中许多都重申了同样的基本建议,但提供了更多细节。当一个问题已经有一个被接受和高度赞成的答案时,这一点尤其重要,就像这里的情况一样,因为这种表达方式已经被 OP 和社区验证为有用。在这些情况下添加新答案很好,但您应该确保您确实在贡献新的东西。
    【解决方案3】:

    这里的 30 个答案都不适合我。我需要:

    1. 删除 node_modules 和 package-lock.json
    2. npm 缓存清理 --force
    3. npm install -g @angular/cli
    4. npm i --package-lock-only
    5. npm ci

    呼!

    【讨论】:

    • 哇,浪费了几个小时,我再也回不来了。哈哈!完成了这项工作,非常感谢你?
    • 删除 package-lock.json 解决了我在 Windows 上的 Vue.js 项目的问题!
    • 这解决了我的问题:npm cache clean --force 非常感谢
    • 它有效,兄弟。谢谢
    【解决方案4】:

    这个错误可能是由许多不同的事情引起的。也许你的全局包在某种程度上被破坏了,我建议做以下事情。

    1 Install Node Version Manager (or NVM for Windows) and install Node version 10.16.1. This is enough for angular 9 and from my experience, it is the most stable version for development. This should also change your NPM version so that may also help.
    
    2 Uninstall global angular package npm uninstall -g @angular/cli
    
    3 Force clear cache npm cache clean --force
    
    4 You can also try clearing your %temp% and %roaming% AppData/npm-cache
    
    5 install latest angular package npm install -g @angular/cli@<your-version>
    
    6 if this error still occurs, consider using another shell.
    

    来源-https://www.codegrepper.com/code-examples/javascript/npm+ERR%21+Unexpected+end+of+JSON+input+while+parsing+near+%27...babel-plugin-istanbul%27+npm+ERR%21+A+complete+log+of+this+run+can+be+found+in%3A+npm+ERR%21+C%3A%5CUsers%5Csapho%5CAppData%5CRoaming%5Cnpm-cache%5C_logs%5C2020-08-26T20_37_45_303Z-debug.log+Aborting+installation

    【讨论】:

      【解决方案5】:

      如果您正在寻找 npm install 并遇到相同类型的错误

      删除 package-lock.json 和 npm cache clean --force 并尝试

      【讨论】:

        【解决方案6】:

        首先卸载现有的npm包: npm uninstall -g create-react-app (-g 如果你全局安装) 其次: npm 缓存清理 --force 第三: npm install -g create-react-app@latest 和 create-react-app my-app 再次。

        【讨论】:

          【解决方案7】:
          npm uninstall -g angular-cli
          
          npm cache clear --force
          

          删除此文件夹目录(在 Windows 中)

          rmdir C:\Users\<ProfileName>\AppData\Roaming\npm
          rmdir C:\Users\<ProfileName>\AppData\Roaming\npm-cache
          

          【讨论】:

            【解决方案8】:

            刚刚在我的React App中添加'radium'包时遇到在解析附近时JSON输入意外结束。 .事实上,即使尝试将 NPM 更新到最新版本,我也遇到了这个问题。

            无论如何,NPM 在清除缓存后不起作用,现在也不会更新到最新版本,但通过 Yarn 添加包对我来说是诀窍。

            因此,如果您急于解决此问题但无法解决,请尝试 yarn 而不是 npm

            编码愉快!

            更新

            在尝试了几件事之后,sudo npm cache clean --force 终于为我工作了。

            这可能是您网络中的临时故障或 npm 注册表中的其他问题。

            【讨论】:

              【解决方案9】:

              即使npm cache clean --force

              尝试在admin文件夹中执行安装cmd。
              IE C:\用户\管理员
              这对我有用。

              【讨论】:

                【解决方案10】:

                由于缓存或节点包管理器版本过时而发生这种情况 我刚刚更新了我的 NPM 它工作正常 这是将 Npm 更新到最新版本的命令

                npm i npm@latest -g
                

                更新 NPM 后运行你想要的命令

                【讨论】:

                  【解决方案11】:

                  尝试设置

                  npm config set strict-ssl false

                  然后尝试运行,

                  npm install -g @angular/cli

                  【讨论】:

                    【解决方案12】:
                    npm cache clean --force
                    npm update
                    

                    不要忘记执行“npm update”。这是非常重要的一步。

                    【讨论】:

                      【解决方案13】:

                      我的案例 - Windows 7(在需要的时候没有比这更好的了)。 帮助了我以下:

                      1. 从 C:\Users\username\AppData\Roaming\npm-cache 中删除所有内容

                      1. 删除 package-lock.json

                      【讨论】:

                      • 删除 package-lock.json 解决了我在 Windows 上的 Vue.js 项目的问题!
                      【解决方案14】:

                      这些命令对我有用

                      sudo npm cache clean --force
                      
                      sudo npm cache verify
                      
                      sudo npm i npm@latest -g
                      

                      【讨论】:

                        【解决方案15】:

                        如果 npm cache clean --force 不能解决问题,请尝试删除 ~/.npm 目录 (*nix/macOS)。这是节点存储其缓存、锁、日志、全局包(除非您使用nvm)和通过npx 安装的模块的目录。

                        首先,备份您当前的~./npm 目录:

                        mv ~/.npm ~/.npm-backup
                        

                        现在尝试再次运行您的 npm 命令。这将创建一个新的~/.npm 目录。如果问题得到解决,您可以安全地删除备份。在此之前,您可能需要查看安装在您的~/.npm-backup 目录中的全局包,以便您可以使用npm i -g [package] 重新安装它们。

                        rm -rf ~/.npm-backup
                        

                        如果问题没有解决,您可以恢复备份:

                        rm -rf ~/.npm
                        mv ~/.npm-backup ~/.npm
                        

                        小心那些rm 命令,伙计们!

                        【讨论】:

                          【解决方案16】:

                          我遇到过这个问题,我在 Stackoverflow 上尝试了所有答案,但对我没有用,最后我找到了解决这个问题的方法:

                          • 首先你必须卸载nodejs并删除所有与他相关的文件
                          • 进入“注册编辑器”并搜索所有“nodejs”、“node.js”并删除它们
                          • 重新启动计算机
                          • 然后重新安装 nodejs,然后安装 angular。

                          对我有用

                          【讨论】:

                            【解决方案17】:

                            您可以使用 yarn 包管理器代替 npm。

                            它为我解决了这个问题

                            【讨论】:

                              【解决方案18】:

                              对我来说,我必须再次克隆我的分支并执行npm install

                              【讨论】:

                                【解决方案19】:

                                我通过首先使用清理缓存解决了这个问题

                                npm cache clean --force
                                

                                然后

                                npm install -g @angular/cli
                                

                                【讨论】:

                                  【解决方案20】:

                                  运行以下代码后出现错误 (file already exists --force to overwrite):

                                  npm cache clean --force
                                  npm install -g @angular/cli
                                  

                                  我解决了这个问题:

                                  npm i -g --force npm
                                  

                                  确保运行第一个命令以刷新 npm 的缓存。

                                  【讨论】:

                                    【解决方案21】:

                                    这为我解决了:

                                    以管理员身份打开 Windows Powershell

                                    npm cache clean --force
                                    npm install -g @angular/cli
                                    

                                    https://devblogs.microsoft.com/premier-developer/getting-started-with-node-js-angular-and-visual-studio-code/

                                    【讨论】:

                                    • 为我工作!但需要以管理员身份打开终端
                                    • @McEmmy :我照你说的做了..但它仍然弹出问题Unexpected token , in JSON at position 366360 while parsing near '... } npm ERR! } npm ERR! }, npm ERR! "webpack-log":...'
                                    • 可以,但是当我在C:\Users\[user-name]\AppData\Roaming\npm主目录下运行它时
                                    • 它有效,但它只是让每个 npm 相关问题都令人沮丧,几乎所有问题都归结为删除 node_modules/ 或清理缓存
                                    • 对我来说超级烦人的是,当您安装数百个软件包并且其中一个失败时,无法分辨是哪一个。这些 npm 错误日志并没有什么用处。
                                    【解决方案22】:

                                    错误:npm 错误!在 '...ore-js":"3.0.0-beta.1

                                    附近解析时 JSON 输入意外结束

                                    全局安装 expo CLI 时会发生这种情况,这对我有用!

                                    npm cache clean --force
                                    

                                    【讨论】:

                                      【解决方案23】:

                                      在此之后npm cache clean --force

                                      也许你可以挂断或等待进一步执行

                                      npm WARN 使用 --force 我当然希望你知道你在做什么。

                                      所以你也可以使用这个。这解决了我的问题。

                                      npm install --cache /tmp/empty-cache

                                      【讨论】:

                                        【解决方案24】:

                                        我解决了这个问题

                                        先删除package-lock.json

                                        npm cache clean --force
                                        

                                        然后更新 npm

                                        npm i npm@latest -g
                                        

                                        然后使用 npm install 命令

                                        npm install 
                                        

                                        【讨论】:

                                          【解决方案25】:

                                          我用这一个班轮解决了我的问题

                                          npm cache clean --force
                                          

                                          它一直像魅力一样起作用。我爱一个班轮。 注意:由于它是全新安装,因此我无需担心清空 npm 缓存。

                                          【讨论】:

                                            【解决方案26】:

                                            如果

                                            npm cache clean --force
                                            

                                            不起作用。 试试

                                            npm cache clean --force
                                            npm update
                                            

                                            【讨论】:

                                            • 这个答案应该会得到更多的选票。更新是重要的一步,我也浪费了将近 3 个小时,因为我找不到这个答案
                                            • 截至 2020 年 5 月,这是唯一能真正完美地解决工作流错误的解决方案
                                            • 毫无疑问,这确实是一个完美的答案。唯一的解决方案对我有用。
                                            • 我也是+1,它工作得很好,而且确实是唯一一个在失去几天尝试修复其他所有东西之后有效的解决方案......
                                            • 截至 2020 年 6 月,它对我有用。请投票给这个答案
                                            【解决方案27】:

                                            您可以设置一个临时文件夹,而不是清除缓存:

                                            npm install --cache /tmp/empty-cache
                                            

                                            npm install --global --cache /tmp/empty-cache
                                            

                                            从 npm@5 开始,npm 缓存可以从损坏问题中自我修复,并且从缓存中提取的数据保证有效。如果您想确保一切一致,请改用npm cache verify。另一方面,如果您正在调试安装程序的问题,您可以使用npm install --cache /tmp/empty-cache 来使用临时缓存而不是核对实际缓存。

                                            【讨论】:

                                              【解决方案28】:

                                              npm cache clean --force 为我工作

                                              错误已解决:

                                              $ npm install -g gulp npm WARN deprecated gulp-util@3.0.8: gulp-util is deprecated - 按照https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5 的指南替换它 npm 错误!在“.../RGs88STtAtiMP3tCiNdU”附近解析时 JSON 输入意外结束

                                              npm 错误!可以在以下位置找到此运行的完整日志: npm 错误! C:\Users\admin\AppData\Roaming\npm-cache_logs\2018-11-20T07_38_56_733Z-debug.log

                                              【讨论】:

                                                【解决方案29】:

                                                这解决了npm cache clean --force

                                                【讨论】:

                                                  【解决方案30】:

                                                  我使用 Windows 并删除了下面列出的所有文件,我的问题得到了解决 C:\Users{{您的用户名}}\AppData\Roaming\npm-cache

                                                  【讨论】:

                                                    猜你喜欢
                                                    • 2020-09-18
                                                    • 1970-01-01
                                                    • 2021-01-04
                                                    • 1970-01-01
                                                    • 1970-01-01
                                                    • 2019-10-16
                                                    • 1970-01-01
                                                    • 2020-05-24
                                                    相关资源
                                                    最近更新 更多