angular-cli使用问题记

一、解决被墙的问题

方法1:设置代理

npm config set proxy=http://127.0.0.1:6152

npm config set https_proxy=http://127.0.0.1:6152

查看刚刚设置的代理

npm config list

删除刚刚配置的代理

npm config delete proxy

npm config delete proxy

方法2、安装nrm切换源

npm install -g nrm

nrm use cnpm 则切换成了cnpm的源

方法3、安装cnpm

npm install -g cnpm

使用cnpm install xxx进行安装

二、安装angular-cli

安装最新版本的cli

npm install -g @angular/cli@latest

查看版本

ng -v

我在这里安装的时候没有报错,在运行此命令的时候报了个错,如下:

Cannot read property 'set' of null

TypeError: Cannot read property 'set' of null

at GeneratedSchemaClass.$$alias (/usr/local/lib/node_modules/@angular/cli/node_modules/@ngtools/json-schema/src/schema-class-factory.js:69:33)

at CliConfig.alias (/usr/local/lib/node_modules/@angular/cli/models/config/config.js:41:29)

at Function.CliConfig.fromProject (/usr/local/lib/node_modules/@angular/cli/models/config.js:65:23)

at Object. (/usr/local/lib/node_modules/@angular/cli/commands/serve.js:6:33)

at Module._compile (module.js:570:32)

at Object.Module._extensions..js (module.js:579:10)

at Module.load (module.js:487:32)

at tryModuleLoad (module.js:446:12)

at Function.Module._load (module.js:438:3)

at Module.require (module.js:497:17)

at require (internal/module.js:20:19)

at Class.includedCommands (/usr/local/lib/node_modules/@angular/cli/addon/index.js:23:16)

at /usr/local/lib/node_modules/@angular/cli/ember-cli/lib/models/project.js:316:61

at Array.forEach (native)

at Project.addonCommands (/usr/local/lib/node_modules/@angular/cli/ember-cli/lib/models/project.js:315:15)

at Project.eachAddonCommand (/usr/local/lib/node_modules/@angular/cli/ember-cli/lib/models/project.js:350:30)

at module.exports (/usr/local/lib/node_modules/@angular/cli/ember-cli/lib/cli/lookup-command.js:33:13)

at CLI. (/usr/local/lib/node_modules/@angular/cli/ember-cli/lib/cli/cli.js:42:26)

at tryCatch (/usr/local/lib/node_modules/@angular/cli/node_modules/rsvp/dist/rsvp.js:538:12)

at invokeCallback (/usr/local/lib/node_modules/@angular/cli/node_modules/rsvp/dist/rsvp.js:553:13)

at publish (/usr/local/lib/node_modules/@angular/cli/node_modules/rsvp/dist/rsvp.js:521:7)

at flush (/usr/local/lib/node_modules/@angular/cli/node_modules/rsvp/dist/rsvp.js:2373:5)

at _combinedTickCallback (internal/process/next_tick.js:67:7)

at process._tickCallback (internal/process/next_tick.js:98:9)

原因:我是在一个已经通过上个版本angular-cli生成的项目里运行这个的,坑啊,坑了我好久

三、升级angular-cli

npm uninstall -g @angular/cli

npm cache clean

npm install -g @angular/cli@latest

四、将ng设置成使用cnpm

ng set --global packageManager=cnpm

你可能感兴趣的:(angular-cli使用问题记)