Fixing EACCES error when deploying Node 8 apps on Amazon Elastic Beanstalk
Recently, when working on deploying a nodejs app for a customer on Elastic Beanstalk and was encountering an issue during the deployment. Here’s the error from the eb-activity.log.
gyp verb `which` failed code: 'ENOENT' } gyp verb check python checking for Python executable "python" in the PATH gyp verb `which` succeeded python /usr/bin/python gyp verb check python version `/usr/bin/python -c "import platform; print(platform.python_version());"` returned: "2.7.12\n" gyp verb get node dir no --target version specified, falling back to host node version: 8.8.1 gyp verb command install [ '8.8.1' ] gyp verb install input version string "8.8.1" gyp verb install installing version: 8.8.1 gyp verb install --ensure was passed, so won't reinstall if already installed gyp verb install version is already installed, need to check "installVersion" gyp verb got "installVersion" 9 gyp verb needs "installVersion" 9 gyp verb install version is good gyp verb get node dir target node version installed: 8.8.1 gyp verb build dir attempting to create "build" dir: /tmp/deployment/application/node_modules/node-sass/build gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied, mkdir '/tmp/deployment/application/node_modules/node-sass/build' gyp ERR! System Linux 4.9.58-18.55.amzn1.x86_64 gyp ERR! command "/opt/elasticbeanstalk/node-install/node-v8.8.1-linux-x64/bin/node" "/tmp/deployment/application/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /tmp/deployment/application/node_modules/node-sass gyp ERR! node -v v8.8.1 gyp ERR! node-gyp -v v3.6.2 gyp ERR! not ok Build failed with error code: 1 npm WARN firstname.lastname@example.org No license field. npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! email@example.com postinstall: `node scripts/build.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the firstname.lastname@example.org 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! /tmp/.npm/_logs/2017-11-17T21_10_59_638Z-debug.log Running npm install: /opt/elasticbeanstalk/node-install/node-v8.8.1-linux-x64/bin/npm Setting npm config jobs to 1 npm config jobs set to 1 Running npm with --production flag Failed to run npm install. Snapshot logs for more details. UTC 2017/11/17 21:10:59 cannot find application npm debug log at /tmp/deployment/application/npm-debug.log
The way that we fixed this issue is by using an .ebextensions file to overwrite the 50npm.sh file. Just create the following as an .ebextensions file and add it to the base of your project. When the project is deployed on Elastic Beanstalk, it will overwrite the default file and run npm install with the –unsafe-perm flag.
files: "/opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh": mode: "000755" owner: root group: users content: | #!/bin/bash #============================================================================== # This is a fix for the issue where when you install node-sass it gets permission problems # This will fix #============================================================================== set -xe #/opt/elasticbeanstalk/containerfiles/ebnode.py --action npm-install export PATH="/opt/elasticbeanstalk/node-install/node-v8.8.1-linux-x64/bin:$PATH"; cd /tmp/deployment/application && npm install --unsafe-perm --production
Hopefully this can help someone who runs into this problem in the future.0