Error: EACCES: permission denied when running `npm install` on Elastic Beanstalk
I had this problem! You can use ebextensions to create a post-deploy script that changes the permissions of the tmp/npm/.locks
folder.
In your node.js project, create a .ebextensions
folder if you haven't got one already. Then, add a new config file, e.g. 00_create_postdeploy_script.config
, with the following yaml:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_fix_node_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm/_locks/
When you deploy, this will create a script in /opt/elasticbeanstalk/hooks/appdeploy/post
called 99_fix_node_permissions.sh
, which looks like this:
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm/_locks/
Because it's in that post
folder, it will be run automatically after your app has deployed -- and hence change the permissions as required.
EDIT: If you're having trouble with the permissions of the whole .npm
folder, then you should change the last line of the config file to:
chown -R nodejs:nodejs /tmp/.npm/