Aws-sam-cli: macOS npm installation failed

Created on 19 Sep 2017  路  16Comments  路  Source: aws/aws-sam-cli

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

[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: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. (/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! [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.

Most helpful comment

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

> [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.2/sam_0.2.2_darwin_amd64.tar.gz
+ [email protected]
added 73 packages in 13.952s

All 16 comments

Resolved, after further searching it was an error on my part.
I ran the following and it installed correctly.
sudo chown -R whoami ~/.npm
sudo chown -R whoami /usr/local/lib/node_modules

So after it did install, I ran sam --version and received the following errors.
npm install -g aws-sam-local

[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.0/sam_0.2.0_darwin_amd64.tar.gz

  • [email protected]
    added 75 packages in 3.936s
    ~ myaccount$ sam --version
    fatal error: runtime: bsdthread_register error

runtime stack:
runtime.throw(0x1877680, 0x21)
/home/ubuntu/bin/go/src/runtime/panic.go:596 +0x95 fp=0x7fff5fbffac0 sp=0x7fff5fbffaa0
runtime.goenvs()
/home/ubuntu/bin/go/src/runtime/os_darwin.go:108 +0xa0 fp=0x7fff5fbffaf0 sp=0x7fff5fbffac0
runtime.schedinit()
/home/ubuntu/bin/go/src/runtime/proc.go:486 +0xa1 fp=0x7fff5fbffb30 sp=0x7fff5fbffaf0
runtime.rt0_go(0x7fff5fbffb68, 0x2, 0x7fff5fbffb68, 0x0, 0x0, 0x2, 0x7fff5fbffc90, 0x7fff5fbffc94, 0x0, 0x7fff5fbffc9e, ...)
/home/ubuntu/bin/go/src/runtime/asm_amd64.s:158 +0x183 fp=0x7fff5fbffb38 sp=0x7fff5fbffb30

Did you download the build yourself or did npm install do it for you? Because it has downloaded a Mac build (darwin) and not a Linux one. That's the reason for the problem

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

Any update regarding this issue? I'm also receiving it.

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

> [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.2/sam_0.2.2_darwin_amd64.tar.gz
+ [email protected]
added 73 packages in 13.952s

I've face same kind of issue but on Ubuntu.

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

npm -g install go-npm # [email protected] 
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 [email protected] 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%E2%80%90wide-installation as opposed to nvm, brew, or manually downloading from https://nodejs.org/download )

Seeing this error also with the following

Ubuntu 16.04
NodeJS 6.12.3
NPM 5.6.0

Getting this error too. Running

sudo npm install -g aws-sam-local

results in this error:

`> [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:885: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. (/usr/local/lib/node_modules/aws-sam-local/node_modules/go-npm/bin/index.js:212:17)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693: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.`

Never use sudo with npm install. You have a directory permissions issue somewhere in your directory structure. This is usually caused by using sudo in the first place. Your directory at '/usr/local/lib/node_modules' is probably owned by root. To solve this, you can either chown directories back to yourself until you've got them all, or you can sudo npm -g uninstall modules until you've uninstalled everything that was installed via sudo.

This is a common problem, and it's a pain to fix. It is almost always caused by the use of sudo. Once you've got your directory permissions worked out, then npm install -g aws-sam-local will work on MacOSX

Couple of thing I鈥檒l point out that makes that diagnosis a bit suspect:

  • multiple people are having the same issue.
  • I only resorted to using sudo on this project because of the error about permissions trying to install this project (go figure).
  • I鈥檝e been using npm all week on other projects - no issues whatsoever.

@Gribbs I understand that this seems suspicious. I don't represent AWS or the SAM Local team. I'm just another person trying to help out, so take my advice with a grain of salt.

My point about sudo is that you probably previously installed something with sudo, before starting this project, which is why you started having permissions issues when trying to install SAM Local.
See the npm documentation at these links:
https://docs.npmjs.com/getting-started/fixing-npm-permissions
https://docs.npmjs.com/getting-started/installing-npm-packages-globally

Quoted: "Test: Download a package globally without using sudo."

Thanks @michaelj-smith. I do appreciate the help and I think you are right. I鈥檝e had my Mac re-imaged of late and might have got lazy. I鈥檒l try grepping my history and see if I can chase down a naughty sudo :)

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.

Not applicable anymore. Latest release should fix this - https://github.com/awslabs/aws-sam-cli/releases/tag/v0.3.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TaylorHG picture TaylorHG  路  27Comments

walkerlangley picture walkerlangley  路  41Comments

kaukas picture kaukas  路  24Comments

oldnerd picture oldnerd  路  25Comments

dinvlad picture dinvlad  路  27Comments