【问题标题】:Latest Angular cli fails to create new app on Windows最新的 Angular cli 无法在 Windows 上创建新应用程序
【发布时间】:2020-05-27 16:35:20
【问题描述】:

在我的 Windows 10 机器上,我尝试使用 ng new myapp(cli 版本 9.0.1)和 Angular v9 创建最新的 Angular 应用程序。 (节点版本v12.15.0)

我已经从 stackoverflow 的相关问题中尝试了以下内容:

  1. 卸载 Angular cli (npm uninstall -g @angular/cli)
  2. npm 缓存清理和 npm 缓存验证
  3. 重新安装 Node JS
  4. 再次安装 angular npm install -g @angular/cli
  5. 尝试在管理员模式下运行 cmd

我收到以下错误:

...
CREATE myapp2/e2e/src/app.po.ts (301 bytes)
- Installing packages...npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
npm ERR! Unexpected end of JSON input while parsing near '...strument":"^1.0.0-alp'
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\jayds\AppData\Roaming\npm-cache\_logs\2020-02-12T07_00_06_637Z-debug.log
× Package install failed, see above.
The Schematic workflow failed. See above.

来自日志文件:

...
5026 silly saveTree +-- tslib@1.10.0
5026 silly saveTree +-- tslint@5.18.0
5026 silly saveTree +-- typescript@3.7.5
5026 silly saveTree `-- zone.js@0.10.2
5027 verbose stack SyntaxError: Unexpected end of JSON input while parsing near '...strument":"^1.0.0-alp'
5027 verbose stack     at JSON.parse (<anonymous>)
5027 verbose stack     at parseJson (C:\Users\jayds\Downloads\Softwares\nodejs\node_modules\npm\node_modules\json-parse-better-errors\index.js:7:17)
5027 verbose stack     at C:\Users\jayds\Downloads\Softwares\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\body.js:96:50
5027 verbose stack     at runMicrotasks (<anonymous>)
5027 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:94:5)
5028 verbose cwd C:\Users\jayds\Projects\myapp2
5029 verbose Windows_NT 10.0.17763
5030 verbose argv "C:\\Users\\jayds\\Downloads\\Softwares\\nodejs\\node.exe" "C:\\Users\\jayds\\Downloads\\Softwares\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "--quiet"
5031 verbose node v12.15.0
5032 verbose npm  v6.13.4
5033 error Unexpected end of JSON input while parsing near '...strument":"^1.0.0-alp'
5034 verbose exit [ 1, true ]

令人惊讶的是,它在我朋友的 Mac Book 上工作。我多次尝试在 Windows 上重新安装 node 和 angular cli,但它仍然给我这个错误。

有人可以帮我解决这个问题并让它在 Windows 10 上运行吗?

注意:我知道还有其他与此相关的问题,但发布的问题已过时,并且使用了不同版本的 Angular。虽然我也尝试过他们的解决方案,但我没有运气。

【问题讨论】:

标签: node.js angular typescript npm angular-cli


【解决方案1】:

请根据https://angular.io/guide/setup-local#nodejs,使用目前为 12 的 LTS 节点版本检查您的节点版本为 Angular 9, 如果您在使用npm install -g @angular/cli 安装角度时遇到与模块(错误-ex)相关的问题,如 404 响应,请在您的终端 npm config set registry https://skimdb.npmjs.com/registry 中尝试此命令, 然后再试npm install -g @angular/cli

【讨论】:

    【解决方案2】:

    作为临时修复,您可以直接从 GitHub 手动安装“error-ex”模块,然后按照此处 facebook/create-react-app#8465(评论)中的说明安装您的依赖项

    $ npm i https://github.com/Qix-/node-error-ex

    $ npm i

    【讨论】:

      【解决方案3】:
      npm cache clean --force
      npm install -g @angular/cli@latest
      

      【讨论】:

      • 不鼓励使用纯代码的答案。请解释您的答案为何以及如何解决问题。
      猜你喜欢
      • 2017-08-14
      • 2019-03-06
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      相关资源
      最近更新 更多