我的项目一直运行到现在(我对node_modules文件进行了一些修改)。
当我尝试“ng”命令时,我收到此错误:
/usr/lib/node_modules/angular-cli/upgrade/version.js:34
? this._version.match(/^(\d+)\.(\d+)(?:\.(\d+))?(?:-(alpha|beta|rc)\.(.*))?$/).slice(1)
^
TypeError: Cannot read property 'slice' of null
at Version._parse (/usr/lib/node_modules/angular-cli/upgrade/version.js:34:91)
at Version.get [as major] (/usr/lib/node_modules/angular-cli/upgrade/version.js:43:40)
at Function.Version.isPreWebpack (/usr/lib/node_modules/angular-cli/upgrade/version.js:142:24)
at Function.Version.assertPostWebpackVersion (/usr/lib/node_modules/angular-cli/upgrade/version.js:126:18)
at /usr/lib/node_modules/angular-cli/bin/ng:24:15
at /usr/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:45:21
at ondir (/usr/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:188:31)
at /usr/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:154:39
at onex (/usr/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:94:22)
at /usr/lib/node_modules/angular-cli/node_modules/resolve/lib/async.js:25:18
我的npm版本是3.10.8,我的节点版本是6.9.1。我必须尝试卸载并重新安装angular-cli,但它不会改变任何东西......任何想法?
答案 0 :(得分:0)
我遇到了这个问题,并将angular-cli.json文件中引用的版本从常规测试版(即1.0.0-beta
)更改为特定的测试版,例如1.0.0-beta.26
,因此常规表达式(注意最后\.
)将正确匹配并返回数组,而不是null
。
// angular-cli.json
{
"project": {
"version": "1.0.0-beta.26",
"name": "name"
},...
}