[Solved] Serverless CLI install failure on macOS

I’m trying to install Serverless CLI with npm install -g serverless but fails with an error (see below). I have the latest versions of both node and npm. If I run as sudo it still fails (see below). Any advice welcomed.

node v9.4.0
npm v5.6.0
macOS 10.13.3

Error when running npm install -g serverless:

Jeremys-iMac:~ jeremy$ npm install -g serverless
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!  { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR!   stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib/node_modules' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jeremy/.npm/_logs/2018-01-30T14_32_21_908Z-debug.log

Error when running sudo npm install -g serverless:

Jeremys-iMac:degree-calc-api jeremy$ sudo npm install -g serverless
/usr/local/bin/serverless -> /usr/local/lib/node_modules/serverless/bin/serverless
/usr/local/bin/sls -> /usr/local/lib/node_modules/serverless/bin/serverless
/usr/local/bin/slss -> /usr/local/lib/node_modules/serverless/bin/serverless

> spawn-sync@1.0.15 postinstall /usr/local/lib/node_modules/serverless/node_modules/spawn-sync
> node postinstall

shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
          cwd = process.cwd();

Error: EACCES: permission denied, uv_cwd
    at Object.resolve (path.js:1175:25)
    at startup (bootstrap_node.js:174:32)
    at bootstrap_node.js:617:3
npm ERR! errno 1
npm ERR! spawn-sync@1.0.15 postinstall: `node postinstall`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the spawn-sync@1.0.15 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/jeremy/.npm/_logs/2018-01-30T14_06_49_435Z-debug.log
1 Like

Try sudo npm install serverless -g

Or install the framework locally in the project folder npm install serverless --save-dev

when installing locally reference serverless like ./node_modules/.bin/serverless deploy or with npx serverless deploy


Thanks very much for your reply, David. I’ve already tried prefixing with sudo and that failed too (see second error block above). Good to know I have the option of installing locally.

I’d like to get to the bottom of the global install issue. I had no trouble installing the framework on my MacBook Pro a few weeks ago. Possibly has something to do with the version of node or npm that I’m running on my iMac?

macOS 10.12.6

I switched to 9.4.0 and was able to install serverless globally just fine.

Node version doesn’t seem to affect the install for me at least but just to eliminate that possibility have you tried a lower version? I use 6.11.5 since Google Cloud Function only supports that. Also, do you use a version manager like NVM?

Thanks, Eric.

I wasn’t using NVM but I am now.

Did what you suggested and tried a lower version (I went for 6.11.5 since you said that was working for you) and I’m happy to report that npm install -g serverless completed without an error.

Thanks again!


Woot! Glad to help Jeremy :tada:

Holler if you have any other issues

It worked for me. Thank you!

Thanks! helped a lot

Works only when use npx serveless. Tks bro!