简体   繁体   中英

“cannot find module” when installing npm modules on windows

I am new to NodeJS. I am trying to use npm on Windows 8.

I have installed using chocolatey , cinst nodejs.install (version 0.10.17 ). I installed as administrator (and would prefer to run npm as a normal user).

Node itself seems to be working, I can use the REPL to run simple programs.

If I try to install something using npm, I get cannot find module :

> node npm install express

module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\Users\Klas\Documents\My Dropbox\mina egna\tech\node\webserver\npm'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

I have read the answers on Nodejs cannot find installed module on Windows? but unfortunately it is still unclear to me what I have to do.

I have tried setting NODE_PATH :

  1. In trying to follow this answer , I have tried setting it to C:\\Users\\Klas\\AppData\\Roaming\\npm\\node_modules (but I had to create both the npm and the subfolder node_modules myself)
  2. I have tried creating a folder c:\\node\\node_module (according to this advice , even though the installation did not even create a c:\\node folder) and setting it to that.
  3. I have tried setting it to C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules (which did exist after installation)
  4. I have also tried to create a node_modules folder below the current working directory. As I understand it that is where local npm will be installed?

None of these helped. So it seems to me that setting NODE_PATH is not the solution?

Using the -g flag makes no difference (I would prefer not to use it).

I get the same error both as normal user and as administrator (I would prefer to be a normal user).

I get the same error no matter where I execute the command, except when I do it in C:\\Program Files\\nodejs , where I get

basedir=`dirname "$0"`
       ^
SyntaxError: Unexpected token ILLEGAL
   at Module._compile (module.js:439:25)

没有使用Windows,但是我很确定它也只是在Windows上进行npm install express

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM