【问题标题】:npm ERR! Unexpected end of JSON input while parsing near '...ain" : "src/index.js"' while running npm install -g @angular/clinpm 错误!在运行 npm install -g @angular/cli 时在“...ain”附近解析时 JSON 输入意外结束:“src/index.js”
【发布时间】:2023-03-07 05:57:01
【问题描述】:

运行命令 npm install -g @angular/cli 时出现上述错误 完整的日志如下

verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...ain" : "src/index.js"'
78 verbose stack at JSON.parse (<anonymous>)
78 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
78 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50
78 verbose stack at processTicksAndRejections (internal/process/task_queues.js:97:5)
79 verbose cwd C:\Users\E079233\Coinnov\CoInnovUI
80 verbose Windows_NT 10.0.17763
81 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "@angular/cli"
82 verbose node v12.18.2
83 verbose npm v6.14.5
84 error Unexpected end of JSON input while parsing near '...ain" : "src/index.js"'
85 verbose exit [ 1, true ]

我按照另一个答案的建议尝试了 npm cache clean --force 和 npm install @angular/cli@latest,但没有成功

请提出解决此问题的可能方法。

【问题讨论】:

    标签: node.js angular npm npm-install npm-start


    【解决方案1】:

    如果您偶然发现此线程正在寻找答案,而其他线程中没有任何建议对您有帮助,那么问题可能出在您的私人 npm 注册表中。至于我,它的响应速度很慢,而且我认为,连接最终因超时而关闭,导致 JSON 包元数据无效,并且还将此类无效 JSON 存储在 npm 缓存中。
    对我来说,解决方法是为我们范围内的包显式设置注册表:

    npm config set @myco:registry http://reg.example.com
    

    这确保只有您的公司范围的包是从集合注册表下载的,而其他包是从全局注册表下载的。还要确保你没有被你的 repo 根目录中的本地 .npmrc 文件覆盖这个设置。

    【讨论】:

      【解决方案2】:

      您似乎因为npm而遇到问题。

      请尝试::

      npm cache clean --force

      npm i -g npm

      npm i -g @angular/cli@latest

      npm inpm install 两者相同。请不要混淆

      【讨论】:

      • 我已经试过了。当我尝试运行 npm i -g @angular/cli@latest 时,得到与上述相同的错误
      • 请告诉您正在使用的节点版本
      猜你喜欢
      • 2020-11-01
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2020-09-18
      • 2019-10-16
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      相关资源
      最近更新 更多