【问题标题】:error creating new project using angular cli使用 Angular cli 创建新项目时出错
【发布时间】:2018-06-21 14:21:54
【问题描述】:

我在使用 Angular cli 创建新应用时遇到错误

我试过了:

npm cache clean --force
npm cache verify

但是没用

请看下图

日志:

2174 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...ul-reporter","version'
2174 verbose stack     at JSON.parse (<anonymous>)
2174 verbose stack     at parseJson (C:\Program Files\nodejs\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)
2174 verbose stack     at consumeBody.call.then.buffer (C:\Program Files\nodejs\node_modules\npm\node_modules\pacote\node_modules\make-fetch-happen\node_modules\node-fetch-npm\src\body.js:96:50)
2174 verbose stack     at <anonymous>
2174 verbose stack     at process._tickCallback (internal/process/next_tick.js:188:7)
2175 verbose cwd C:\Users\nielcleoa\Desktop\appsample
2176 verbose Windows_NT 6.1.7601
2177 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--quiet"
2178 verbose node v8.11.3
2179 verbose npm  v5.6.0
2180 error Unexpected end of JSON input while parsing near '...ul-reporter","version'
2181 verbose exit [ 1, true ]

使用的版本:

node version: 8.11.3 
npm version: 5.6.0 
angular-cli version: 6.0.8

【问题讨论】:

  • 你的 NPM、Node、angular-cli 等版本是什么?
  • 节点版本:8.11.3 npm 版本:5.6.0 angular-cli 版本:6.0.8
  • 尝试升级到最新的 angular-cli 版本,然后创建一个新项目npm i -g @angular/cli@latest
  • 我尝试更新,但仍然遇到同样的错误。但是当我升级我的 angular-cli 时,我收到警告说跳过可选依赖项:fsevent@1.2.4 不受支持的平台。我不知道它是否与我的错误有关。
  • 尝试更新到新版本的 npm (npm install -g npm) 看看是否有帮助。顺便说一句,由于您正在运行 Windows,因此可以忽略 fsevent 警告。

标签: node.js angular npm angular5


【解决方案1】:

试试这个。

npm uninstall -g angular-cli
npm cache clean
npm install -g angular-cli@latest

【讨论】:

  • 得到这个错误.. 1402 详细堆栈 SyntaxError: JSON 输入意外结束,同时在'...hint":"*","yui-lint":' 1402 详细堆栈在 JSON 附近进行解析。解析()
  • 运行时npm install -g angular-cli@latest
  • 以管理员身份运行 cmd: npm cache clean --force
【解决方案2】:

您是否正在尝试安装 Angular2+ CLI?

如果是这样,这是命令:

npm install -g @angular/cli

上面 cmets 的命令是旧的 AngularJS CLI,即:npm install -g angular-cli

这里的文档:https://www.npmjs.com/package/@angular/cli

【讨论】:

  • 您的机器上是否安装了这两个 CLI 包?
  • 你能分享一下你的 angular.json 文件是什么样子的吗?看起来这生成了适当的文件,但在安装包时失败。
  • 你的 package.json 呢?我已经阅读了这些文件中注释掉的行可能导致问题的实例
  • 我没有看到任何不寻常的地方。您是否尝试过再次在项目文件夹的根目录中重新运行 npm installng serve
猜你喜欢
  • 2017-01-25
  • 1970-01-01
  • 2022-01-15
  • 2019-01-12
  • 1970-01-01
  • 2018-05-25
  • 2020-01-16
  • 2019-03-06
  • 1970-01-01
相关资源
最近更新 更多