【问题标题】:Weird error when trying to create new angular app尝试创建新的角度应用程序时出现奇怪的错误
【发布时间】:2018-08-28 18:02:26
【问题描述】:

当我尝试使用

创建新的 Angular 应用程序时出现此错误
ng new frontend

这是我得到的错误

npm ERR! Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'

所以我提到了 npm git 问题但我找不到解决方案,他们建议这可能是网络问题,并且有人建议重新安装或更新 nodejs、npm 和 angular cli。我确实通过重新安装所有必需的软件来更新所有内容,但是当我尝试运行以下命令时 -

npm install --save-dev @angular/cli@latest

我仍然遇到同样的错误。请建议我需要做什么来创建一个具有 angular 2+( 4, 5, 6) 的新 ng 应用程序。

更新 根据日志,这是失败的地方-我也尝试过使用较低版本的节点

451 silly fetchPackageMetaData error for typescript@>=2.6.2 <2.10 Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'
452 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'
452 verbose stack     at JSON.parse (<anonymous>)
452 verbose stack     at parseJson (C:\Users\Ganesh\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\node_modules\json-parse-better-errors\index.js:7:17)
452 verbose stack     at consumeBody.call.then.buffer (C:\Users\Ganesh\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\body.js:96:50)
452 verbose stack     at <anonymous>
452 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
453 verbose cwd D:\
454 verbose Windows_NT 10.0.17134
455 verbose argv "D:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Ganesh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "-g" "@angular/cli"
456 verbose node v8.9.4
457 verbose npm  v5.6.0

更新 2 由于我发现安装 Typescript 存在错误,我尝试使用

直接安装 Typescript
 npm i -g typescript

我发现它正在尝试访问一个文件

https://registry.npmjs.org/typescript

而且我还发现 json 中只有一个这样的位置会发生错误。这是新的日志:-

0 info it worked if it ends with ok
1 verbose cli [ 'D:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\Ganesh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'typescript' ]
2 info using npm@5.6.0
3 info using node@v8.9.4
4 verbose npm-session 51a5c57f485d99fd
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 http fetch GET 200 https://registry.npmjs.org/typescript 31ms (from cache)
8 silly fetchPackageMetaData error for typescript@latest Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'
9 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'
9 verbose stack     at JSON.parse (<anonymous>)
9 verbose stack     at parseJson (C:\Users\Ganesh\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\node_modules\json-parse-better-errors\index.js:7:17)
9 verbose stack     at consumeBody.call.then.buffer (C:\Users\Ganesh\AppData\Roaming\npm\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\body.js:96:50)
9 verbose stack     at <anonymous>
9 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
10 verbose cwd D:\
11 verbose Windows_NT 10.0.17134
12 verbose argv "D:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Ganesh\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install" "typescript"
13 verbose node v8.9.4
14 verbose npm  v5.6.0
15 error Unexpected end of JSON input while parsing near '...dSize":36422127},"eng'
16 verbose exit [ 1, true ]

但是现在我该怎么办?请帮助我完成后续步骤。

【问题讨论】:

  • 你当前的 node 和 npm 版本是什么 (npm -v) (node-v)。您是否尝试清理 npm 缓存 (npm cache clean --force) !警告 - 缓存清理会从 npm 中删除缓存,因此您的下一次安装会更慢。
  • @Drag13 是的,我清理了缓存并重新安装了 node 和 npm,但是当我尝试安装 angular Cli 时出现 JSON 解析错误。
  • 所以我假设你有最新的节点和 npm,对吧?尝试安装不是最新的 cli,而是安装特定的 6.1.4
  • @Drag13 npm 版本 6.4.1-next.0 节点版本 v8.11.1 将卸载并尝试使用其他版本。
  • 我指的是特定版本的cli,以及稳定版本的npm

标签: angular npm-install


【解决方案1】:

我找不到问题的答案,因此我尝试在 Windows 10 中使用新用户帐户。它成功了。目前,这对我有所帮助。我仍然对 Windows 中的此类问题感到非常不舒服。

【讨论】:

  • 这是非常有线的,但感谢分享。您介意创建新的错误报告吗?
  • @Drag13 我确实报告了一个问题,因为我不确定这是否是 npm 的错误,并且由于它在我登录另一个帐户的那一刻得到解决,我认为这是一个 Windows 问题。但是,我将创建一个错误报告以防万一它可以帮助某人。感谢合作。
猜你喜欢
  • 2016-01-31
  • 2023-03-07
  • 1970-01-01
  • 2022-11-21
  • 2018-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多