How to resolve 'npm should be run outside of t

2019-01-21 16:01发布

I am new to node.js. I downloaded and install node.js installer from the official site. I have added this installer folder in PATH environment variable and I am able to run programs. But when I try to install some package using npm in node console it shows the error npm should be run outside of the node repl, in your normal shell. I also tried it on a separate console. But it shows command not found though I have added node in the environment variable.

enter image description here

enter image description here

标签: node.js npm
9条回答
萌系小妹纸
2楼-- · 2019-01-21 17:00

If you're like me running in a restricted environment without administrative privileges, that means your only way to get node up and running is to grab the executable (node.exe) without using the installer. You also cannot change the path variable which makes it that much more challenging.

Here's what I did (for Windows)

  1. Throw node.exe into it's own folder (Downloaded the node.exe stand-alone )
  2. Grab an NPM release zip off of github: https://github.com/npm/npm/releases
  3. Create a folder named: node_modules in the node.exe folder
  4. Extract the NPM zip into the node_modules folder
  5. Make sure the top most folder is named npm (remove any of the versioning on the npm folder name ie: npm-2.12.1 --> npm)
  6. Copy npm.cmd out of the npm/bin folder into the top most folder with node.exe
  7. Open a command prompt to the node.exe directory (shift right-click "Open command window here")
  8. Now you will be able to run your npm installers via: npm install -g express

Running the installers through npm will now auto install packages where they need to be located (node_modules and the root)

Don't forget you will not be able to set the path variable if you do not have proper permissions. So your best route is to open a command prompt in the node.exe directory (shift right-click "Open command window here")

查看更多
时光不老,我们不散
3楼-- · 2019-01-21 17:05

It's simple. Press the Windows logo on your keyboard. Then, type node.js command prompt in the search bar and run it. screenshot: run npm outside node repl

查看更多
Juvenile、少年°
4楼-- · 2019-01-21 17:06

You must get directory right path of program(node.js in program files).

such as

enter image description here

and use "npm install -g phonegap"

查看更多
登录 后发表回答