aws-sam-cli: macOS npm installation failed

I am unable to install on macOS using npm. I tried installing as sudo and this still did not work.

MacOS 10.12.6 Node v8.1.3 NPM 5.4.2

aws-sam-local@0.2.0 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:890: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:159:12) at Object.<anonymous> (/usr/local/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:210:17) at Module._compile (module.js:569:30) at Object.Module._extensions…js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Function.Module.runMain (module.js:605:10) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! aws-sam-local@0.2.0 postinstall: go-npm install npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the aws-sam-local@0.2.0 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (3 by maintainers)

Most upvoted comments

Here is the exact sequence that worked on my local a few seconds ago. Don’t forget to leave sudo out when it comes to step 3.

$ sudo chown -R nico ~/.npm $ sudo chown -R nico /usr/local/lib/node_modules $ npm install --global aws-sam-local

Nicos-Air:~ nico$ npm install --global aws-sam-local

> aws-sam-local@0.2.2 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.2/sam_0.2.2_darwin_amd64.tar.gz
+ aws-sam-local@0.2.2
added 73 packages in 13.952s

I am on a mac. Per the installation instructions I used npm install -g aws-sam-local.

Hi, I did this workaround (tested on Ubuntu but should work on Mac with node in /usr/local ):

npm -g install go-npm # go-npm@0.1.8 
npm -g install aws-sam-local --ignore-scripts
cd $(find /usr/local/ -name aws-sam-local)
npm run postinstall

This works and puts the binary in aws-sam-local/node_modules/.bin/sam which I then linked to my node bin.

Might be related to https://github.com/sanathkr/go-npm/pull/3 which looks merged but not released.

Here’s one way to reproduce the EACCES npm error "Failed at the aws-sam-local@0.2.2 postinstall script ‘go-npm install’ " on Ubuntu (or any Linux once you install basics):

sudo su --login
apt-get -y install make gcc
curl -L https://git.io/n-install | N_PREFIX=/usr/local/opt/n bash -s -- -y lts
sh -c "echo 'export N_PREFIX=/usr/local/opt/n; export PATH+=\":\$N_PREFIX/bin\"' >>/etc/profile.d/n-install.sh"
. /etc/profile.d/n-install.sh
node --version
# v6.11.5
npm --version
# 3.10.10
npm -g install aws-sam-local

(This is using https://github.com/mklement0/n-install/wiki/System‐wide-installation as opposed to nvm, brew, or manually downloading from https://nodejs.org/download )

I had installed serverless with sudo. In the end, I uninstalled Node and re-installed Node using Homebrew. I had no problems installing aws-sam-local after this.