npm will not install express?

后端 未结 8 1024
臣服心动
臣服心动 2020-12-23 11:39

I currently have node.js version 0.8.8, and npm 1.1.59 installed.

Whenever I run:

$ npm install -g express

I get this in return:<

相关标签:
8条回答
  • 2020-12-23 11:50

    In my case, instead of the ~/.npm directory being owned by root, it was ~/tmp, which I didn't think to check until one of the error messages finally led me to find. Procedure for fixing is pretty easy, since it's a tmp directory, we can just blow it away and start again with one owned by you.

    sudo rmdir ~/tmp
    mkdir ~/tmp
    
    0 讨论(0)
  • 2020-12-23 11:52

    The solution is:

    1 - chown to your user the .npm folder :

    sudo chown -R Webmaste /Users/webmaste/.npm/
    

    2 - At your test folder or your folder:

    sudo npm install -g express@2.5.8
    

    3 - Invoke express from your actual location:

    /usr/local/share/npm/bin/express
    

    4 -

    sudo cd . && npm install
    

    5 - finally:

    node app
    

    the final message in the console should look like this:

    Express server listening on port 3000 in development mode
    
    0 讨论(0)
  • 2020-12-23 11:54

    run npm cache clean and try to install it again

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

    I had the same problem, and npm cache clear did not fix it. This problem is caused because the .npm directory in your home directory was created with root privileges. Most likely the first npm command you ran was sudo npm -g and now you are trying to npm install in a local directory.

    To solve:

    • sudo chown -R yourusername ~/.npm
    • This may not be necessary but I also had to rmdir ~/tmp

    npm install from package.json should work after this.

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

    Run powershell as administrator, then type:

    Set-ExecutionPolicy RemoteSigned
    

    then try install again.

    0 讨论(0)
  • 2020-12-23 12:08

    As a side note, if you other solutions haven't helped, I have had the same issue and realised what was wrong -- which maybe of interest here.

    I had nodemon running on another project -- when I installed locally express. Check you're not running express on another project and trying to install express on a new project. Just a heads up and hope it helps. By the way, just copied the dependency from the package file, and pasted into my new project and ran npm install and checked, express got installed.

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