npm - npm install -g @angular/cli 因语法错误而失败
问题描述
我有一个在 centos 7 容器上运行的詹金斯工作。一旦容器启动,jenkins 作业就会运行一个脚本来执行
npm install -g @angular/cli
这已经工作了大约一年,但今天它开始失败:
/usr/bin/ng -> /usr/lib/node_modules/@angular/cli/bin/ng
> @angular/cli@8.0.4 postinstall /usr/lib/node_modules/@angular/cli
> node ./bin/postinstall/script.js
/usr/lib/node_modules/@angular/cli/bin/postinstall/analytics-prompt.js:8
(async () => {
^
SyntaxError: Unexpected token (
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/usr/lib/node_modules/@angular/cli/bin/postinstall/script.js:5:1)
npm ERR! Linux 3.10.0-957.1.3.el7.x86_64
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "@angular/cli"
npm ERR! node v6.16.0
npm ERR! npm v3.10.10
npm ERR! code ELIFECYCLE
npm ERR! @angular/cli@8.0.4 postinstall: `node ./bin/postinstall/script.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @angular/cli@8.0.4 postinstall script 'node ./bin/postinstall/script.js'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the @angular/cli package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./bin/postinstall/script.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs @angular/cli
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls @angular/cli
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /app/capman-fe/npm-debug.log
我packages.json
的是这样的:
{
"name": "pman-fe",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
... omitted for brevity ...
},
"devDependencies": {
"@angular-devkit/build-angular": "^0.6.8",
"@angular/cli": "^6.0.8",
"@angular/compiler-cli": "^6.0.3",
"@angular/language-service": "^6.0.3",
"@types/d3": "^5.7.1",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.1",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
解决方案
我能够解决这个错误。问题是,当我安装时,npm
我只是执行了:yum -y install npm
. 我猜我必须使用的容器的 yum 存储库没有最新的npm
rpm 副本。所以我改变了我的安装方式npm
。现在我这样做:
yum install -y gcc-c++ make
curl -sL https://rpm.nodesource.com/setup_10.x | bash -
yum -y install nodejs
node -v
npm -v
npm install -g @angular/cli
根据https://tecadmin.net/install-latest-nodejs-and-npm-on-centos/
推荐阅读
- typescript - 如何在 TypeScript 中导出对象时将接口包装在对象中?
- elasticsearch - 在 X 次数据目录后配置滚动或删除,以防止“空间不足”错误
- javascript - 鼠标快速移动时鼠标光标在应用程序窗口外
- java - JMockit 验证是否调用了私有方法
- core-data - CoreData 与关系 - 如何避免重复更新
- c# - 我缺少什么统一/C#?
- amazon-web-services - AWS IAM 策略中拒绝“ListAccounts”访问
- python - TypeError:“模块”对象不可调用(随机模块)
- python-3.x - 通过 msmtp 为 crontab 发送电子邮件主题和密件抄送
- python - 带有奇怪返回函数的循环?