【问题标题】:error while installing angular/cli using npm使用 npm 安装 angular/cli 时出错
【发布时间】:2018-11-10 05:43:41
【问题描述】:

当我尝试使用此命令安装 angular cli 时

npm install -g @angular/cli

我得到了下面提到的错误

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 
(node_modules\@angular\cli\node_modules\chokidar\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY:  Unsupported platform for 
fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} 
(current: {"os":"win32","arch":"x64"}) 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.1.2 (node_modules\@angular\cli\node_modules\watchpack\node_modules\chokidar\node_modules\fsevents): 
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.1.2 (node_modules\@angular\cli\node_modules\webpack-dev-server\node_modules\chokidar\node_modules\fsevents): 
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) 
npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none was installed. 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-sass@4.9.0 (node_modules\@angular\cli\node_modules\node-sass): 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: node-sass@4.9.0 postinstall: `node scripts/build.js 
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

知道是什么问题吗?

我的node版本是6.9.2,npm版本是3.10.9

【问题讨论】:

  • 将节点更新到 8.9 或更高版本。这是一个较新的要求。然后再试一次。
  • 是的,它确实与节点版本有关,我卸载了节点并安装了v8.11.1,它确实有效。谢谢@R.Richards

标签: node.js angular angular-cli


【解决方案1】:

尝试在您的项目文件夹中使用以下命令:

npm audit fix

如果它仍然显示它只修复了几个漏洞,那么使用下面的命令

npm audit fix --force

Screen shot of the command that I used in my machine

【讨论】:

    【解决方案2】:

    这个警告说明了一切:

    Unsupported platform for fsevents@1.2.4: **wanted** {"os":"darwin","arch":"any"} (**current**: {"os":"win32","arch":"x64"})
    

    只有基于 unix 的系统使用 fsevents,而您使用的是 Windows!

    【讨论】:

    • 我知道只支持基于 unix 的系统,但我不需要在所有构建中都发出警告。您知道在 Windows 上消除此警告的方法吗?
    【解决方案3】:

    首先,您发布的所有内容都是警告,而不是错误。

    这意味着 npm 已经跳过了依赖项。

    如果你将 npm 版本更新到最新版本就可以解决这个问题,使用这个命令:

    npm i -g npm@latest  
    

    // 如果出现权限错误,请使用 sudo

    然后尝试重新安装。

    希望这会有所帮助。

    【讨论】:

    • 在成功更新 npm 后,当我再次尝试安装 angular/cli 时,我收到下面提到的警告 npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.4 (node_modules\@angular\cli\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.4: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"}) + @angular/cli@6.0.7 updated 1 package in 44.551s 并且 ng -v 返回无法识别的命令
    • 你现在的 npm 版本是多少?
    • npm 版本现在是 6.1.0
    • 试试这个npm i -f -g npm@latest
    • 还是一样的警告,无法识别 ng
    【解决方案4】:
    $ npm install -g @angular/cli
    C:\Users\Asus\Desktop\ng -> C:\Users\Asus\Desktop\node_modules\@angular\cli\bin\ng
    npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.7 (node_modules\@angular\cli\node_modules\fsevents):
    npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
    
    + @angular/cli@7.3.2
    added 295 packages from 179 contributors in 120.715s
    

    【讨论】: