在使用
npm install -g aws-sam-local
安装SAM Local时出现以下错误:
ip-10-2-201-246:~ zhouweiliang$ sudo npm install -g aws-sam-local
> [email protected] postinstall /usr/local/lib/node_modules/aws-sam-local
> go-npm install
/usr/local/lib/node_modules/aws-sam-local/node_modules/mkdirp/index.js:90
throw err0;
^
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/aws-sam-local/bin'
at Object.fs.mkdirSync (fs.js:905:18)
at Function.sync (/usr/local/lib/node_modules/aws-sam-local/node_modules/mkdirp/index.js:71:13)
at Object.install (/usr/local/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:161:12)
at Object.<anonymous> (/usr/local/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:212:17)
at Module._compile (module.js:641:30)
at Object.Module._extensions..js (module.js:652:10)
at Module.load (module.js:560:32)
at tryModuleLoad (module.js:503:12)
at Function.Module._load (module.js:495:3)
at Function.Module.runMain (module.js:682:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: `go-npm install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/zhouweiliang/.npm/_logs/2018-04-09T05_38_26_446Z-debug.log
update npm后仍不行,最终使用如下命令解决了问题:
npm config set unsafe-perm=true
ip-10-2-201-246:npm zhouweiliang$ npm config set unsafe-perm=true
ip-10-2-201-246:npm zhouweiliang$ sudo npm install -g aws-sam-local
Password:
> [email protected] postinstall /usr/local/lib/node_modules/aws-sam-local
> go-npm install
Downloading from URL: https://github.com/awslabs/aws-sam-local/releases/download/v0.2.10/sam_0.2.10_darwin_amd64.tar.gz
added 72 packages from 59 contributors in 15.855s
ip-10-2-201-246:npm zhouweiliang$ sam --version
sam version 0.2.10
安装成功。