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

后端 未结 3 1615
鱼传尺愫
鱼传尺愫 2021-02-13 11:49

I\'ve provisioned a default clean node.js app via Elastic Beanstalk, and have a node.js script trying to run npm install inside the project directory (/var/ap

相关标签:
3条回答
  • 2021-02-13 12:26

    The following command will fix the issue. it worked for me.

    sudo chown -R 1000:1000 "/home/user/.npm" 
    
    0 讨论(0)
  • 2021-02-13 12:28

    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/
    
    0 讨论(0)
  • 2021-02-13 12:50

    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.

    0 讨论(0)
提交回复
热议问题