Error: EACCES: permission denied when running `npm install` on Elastic Beanstalk

只谈情不闲聊 提交于 2019-12-03 10:58:52

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/

I have had this problem in past and in my case cleaning the cache fixed my issue. Please try this

npm cache clean

Hope it helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!