安装 @angular-cli 及异常处理

这次安装@angular-cli真的是头疼,自动化安装的东西,跑出了错误。无奈,百度也没找到和我相似错误的博客,只能自己尝试解决,而你的环境和错误很有可能和我的不同,具体还是要看日志去分析原因。

安装@angular/cli

环境

@angular/cli的环境要求是node 6.9.x 和 npm 3.x.x 以上的版本

node -v //查看node版本
npm -v //查看npm版本

如果符合,就可以使用以下命令安装@angular/cli

npm install -g @angular/cli

但是我在这里一直报错,而且满屏的错误信息简直摸不着头脑

尝试安装Angular对Typescript的依赖

先设置一下npm,使用淘宝镜像

npm config set registry https://registry.npm.taobao.org  
npm config set disturl https://npm.taobao.org/dist

然后安装Typescript依赖

npm install -g typescript typings

再次安装@angular/cli,结果还是相同的错误日志

分析日志

冷静了一些,开始分析日志,逐步解决问题

npm WARN @angular-devkit/schematics@0.0.51 requires a peer of @angular-devkit/core@0.0.28 but none is installed. You must install peer dependencies yourself.
npm WARN @schematics/angular@0.1.16 requires a peer of @angular-devkit/core@0.0.28 but none is installed. You must install peer dependencies yourself.

可以看到需要手动安装@angular-devkit/[email protected]。而具体操作还要看日志信息,也许你的问题和我并相同。

npm install -g @angular-devkit/[email protected]

如果不行,那就按一下步骤操作

npm install -g @angular-devkit/schematics
npm install -g @angular-devkit/[email protected] //事实上它是@angular/cli安装成功后在安装的

最终解决

到了这里,我安装@angular-cli还是有问题的,都有点想放弃了。有趣的是,当我尝试着先安装了angular-cli(其实是运行错命令了,只抛出了几个WARN,但是成功的在npm的node_modules下,而之前安装的@angular-cli,node_modules下则根本就没有),再次安装@angular-cli就成功了
angular-cli和@angular/cli可不相同

npm install -g angular-cli
npm install -g @angular/cli

安装@angular-cli的完整错误日志

npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\es5-ext-18d723b2\test\math\log2\implement.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\es5-ext-18d723b2\test\math\log2\index.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\es5-ext-18d723b2\test\math\log2\is-implemented.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\es5-ext-18d723b2\test\math\log2\shim.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\jsonify\package.json'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\jsonify\index.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\jsonify\README.markdown'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\0.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\1.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\2.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\3.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\4.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\index.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\core-js-f22b0c64\stage\pre.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\qs\dist\qs.js'
npm WARN tar ENOENT: no such file or directory, lstat 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\rc\node_modules\minimist\example'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\rc\node_modules\minimist\readme.markdown'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\algs.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\ed-compat.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\errors.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\fingerprint.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\dhe.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\certificate.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\index.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\key.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\private-key.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\signature.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\ssh-buffer.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\utils.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\sshpk\lib\identity.js'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\format.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\_limit.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\_limitLength.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\_limitProperties.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\allOf.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\anyOf.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\coerce.def'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\custom.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\defaults.def'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\definitions.def'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\dependencies.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\enum.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\errors.def'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\_limitItems.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\items.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\missing.def'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\multipleOf.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\not.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\oneOf.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\pattern.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\properties.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\ref.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\required.jst'
npm WARN tar ENOENT: no such file or directory, open 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\ajv\lib\dot\uniqueItems.jst'
npm WARN @angular-devkit/[email protected] requires a peer of @angular-devkit/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN @schematics/[email protected] requires a peer of @angular-devkit/[email protected] but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\@angular\cli\node_modules\fsevents):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: no such file or directory, rename 'c:\MyApps\nvm\npm\node_modules\.staging\fsevents-b99ba2fb\node_modules\aproba' -> 'c:\MyApps\nvm\npm\node_modules\.staging\aproba-d60fd9f8'

npm ERR! code EINTEGRITY
npm ERR! sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q= integrity checksum failed when using sha1: wanted sha1-PFtv1/beCRQmkCfwPAlGdY92c6Q= but got sha1-CdgPhI34ysEA2kE4NtgghYCGpcw=. (2509375 bytes)

最后吐槽一句,npm确实是神器,但是出现错误的时候,真的是满屏的WARN

你可能感兴趣的:(YO.you,are,write,bug!,Angular)