Node.js not working on Amazon Elastic Beanstalk due to directory permissions

I am trying to install a simple Node.js application on Elastic Beanstalk using command line tools.

In my git repository, I ran a command

$ eb deploy 

to deploy the contents of my git repository. It deploys well, but the health state of the application is red.

If I look at the logs on the Elastic Beanstalk website, it tells me the following error in the logs:

 > fsevents@1.0.8 install /tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents > node-pre-gyp install --fallback-to-build gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/build' gyp ERR! stack at Error (native) gyp ERR! System Linux 4.1.17-22.30.amzn1.x86_64 gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v4.3.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-linux-x64/fse.node" "--module_name=fse" "--module_path=/tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-linux-x64" gyp ERR! cwd /tmp/deployment/application/node_modules/nodemon/node_modules/chokidar/node_modules/fsevents gyp ERR! node -v v4.3.0 gyp ERR! node-gyp -v v3.0.3 gyp ERR! not ok 

I tried different things like:

  • Create a directory yourself (directories belong to root).
  • Removing everything from / tmp, so I hope the next time he fixes himself.
  • Removing my node_modules directory.

None of these options work, and I cannot find a workaround or the reason why this is happening. I can run the Node.js application locally and also deploy it to Azure and Heroku without any problems.

+1
amazon-web-services elastic-beanstalk npm-install
source share
2 answers

Spent the whole day debugging this error. Turns out you need a trailing slash for the directories in your .ebignore file.

.ebignore

 node_modules/ 

Without a trailing slash, your local node_modules folder will be loaded by eb - including dev dependencies.

+4
source share

I had a similar problem, but I did not use eb for deployment and did not include node_modules/ in the package. The solution that worked for me was setting unsafe-perm=true in .npmrc - see Beanstalk: Node.js deploy - node -gyp failed due to access denied

+2
source share

All Articles