简体   繁体   English

在Windows上安装npm模块时“找不到模块”

[英]“cannot find module” when installing npm modules on windows

I am new to NodeJS. 我是NodeJS的新手。 I am trying to use npm on Windows 8. 我试图在Windows 8上使用npm。

I have installed using chocolatey , cinst nodejs.install (version 0.10.17 ). 我已经使用Chocolateycinst nodejs.install (版本0.10.17 )进行了安装。 I installed as administrator (and would prefer to run npm as a normal user). 我以管理员身份安装(并且希望以普通用户身份运行npm)。

Node itself seems to be working, I can use the REPL to run simple programs. Node本身似乎正在运行,我可以使用REPL运行简单的程序。

If I try to install something using npm, I get cannot find module : 如果我尝试使用npm安装某些东西, 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? 我已经阅读了Nodejs上的答案, 无法在Windows上找到已安装的模块? but unfortunately it is still unclear to me what I have to do. 但不幸的是,我仍然不清楚该怎么做。

I have tried setting NODE_PATH : 我尝试设置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) 在尝试遵循此答案时 ,我尝试将其设置为C:\\Users\\Klas\\AppData\\Roaming\\npm\\node_modules (但是我必须自己创建npm和子文件夹node_modules
  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. 我曾尝试创建一个文件夹c:\\node\\node_module (根据此建议 ,即使安装甚至没有创建c:\\node文件夹),也都将其设置为该文件夹。
  3. I have tried setting it to C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules (which did exist after installation) 我尝试将其设置为C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules (安装后确实存在)
  4. I have also tried to create a node_modules folder below the current working directory. 我还尝试在当前工作目录下创建一个node_modules文件夹。 As I understand it that is where local npm will be installed? 据我了解,这将在本地安装npm?

None of these helped. 这些都没有帮助。 So it seems to me that setting NODE_PATH is not the solution? 所以在我看来,设置NODE_PATH不是解决方案吗?

Using the -g flag makes no difference (I would prefer not to use it). 使用-g标志没有区别(我宁愿不使用它)。

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 无论我在哪里执行命令,都会收到相同的错误,除了在C:\\Program Files\\nodejs

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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