Npm install failed with “cannot run in wd”

前端 未结 5 1046
梦谈多话
梦谈多话 2020-12-12 10:32

I am trying to get my node environment set up on a new Ubuntu 12.04 instance, with Node 0.8.14 already installed, but I ran into problems when I try to run npm install

相关标签:
5条回答
  • 2020-12-12 10:55

    The only thing that worked for me was adding a .npmrc file containing:

    unsafe-perm = true
    

    Adding the same config to package.json didn't have any effect.

    0 讨论(0)
  • 2020-12-12 11:03

    I fixed this by changing the ownership of /usr/local and ~/Users/user-name like so:

    sudo chown -R my_name /usr/local

    This allowed me to do everything without sudo

    0 讨论(0)
  • 2020-12-12 11:04

    OP here, I have learned a lot more about node since I first asked this question. Though Dmitry's answer was very helpful, what ultimately did it for me is to install node with the correct permissions.

    I highly recommend not installing node using any package managers, but rather to compile it yourself so that it resides in a local directory with normal permissions.

    This article provides a very clear step-by-step instruction of how to do so:

    https://www.digitalocean.com/community/tutorials/how-to-install-an-upstream-version-of-node-js-on-ubuntu-12-04

    0 讨论(0)
  • 2020-12-12 11:05

    The documentation says (also here):

    If npm was invoked with root privileges, then it will change the uid to the user account or uid specified by the user config, which defaults to nobody. Set the unsafe-perm flag to run scripts with root privileges.

    Your options are:

    1. Run npm install with the --unsafe-perm flag:

      [sudo] npm install --unsafe-perm
      
    2. Add the unsafe-perm flag to your package.json:

      "config": {
          "unsafe-perm":true
      }
      
    3. Don't use the preinstall script to install global modules, install them separately and then run the regular npm install without root privileges:

      sudo npm install -g coffee-script node-gyp
      npm install
      

    Related:

    • package.json for global module installation
    0 讨论(0)
  • 2020-12-12 11:18

    I have experienced the same problem when trying to publish my nodejs app in a private server running CentOs using root user. The same error is fired by "postinstall": "./node_modules/bower/bin/bower install" in my package.json file so the only solution that was working for me is to use both options to avoid the error:

    1: use --allow-root option for bower install command

    "postinstall": "./node_modules/bower/bin/bower --allow-root install"
    

    2: use --unsafe-perm option for npm install command

    npm install --unsafe-perm
    
    0 讨论(0)
提交回复
热议问题