Node.js 节点包安装失败,因为节点';It’在我的根目录中查找依赖项

Node.js 节点包安装失败,因为节点';It’在我的根目录中查找依赖项,node.js,filesystems,npm,node-modules,Node.js,Filesystems,Npm,Node Modules,在使用npm安装软件包时,我最近遇到了一个问题,Node无法找到模块/脚本。出于某种原因,它正在查看我的C://目录,而不是C:/myproject/node\u模块。这个图书馆特别麻烦,但我以前也见过这种情况 我正在用节点的v0.10.35运行Win7 x32 这是我在尝试安装节点sass时看到的示例: C:\node\test>npm install node-sass > node-sass@2.0.0-beta install C:\node\test\node_module

在使用
npm
安装软件包时,我最近遇到了一个问题,
Node
无法找到模块/脚本。出于某种原因,它正在查看我的
C://
目录,而不是
C:/myproject/node\u模块
。这个图书馆特别麻烦,但我以前也见过这种情况

我正在用
节点的v0.10.35运行Win7 x32

这是我在尝试安装
节点sass
时看到的示例:

C:\node\test>npm install node-sass
> node-sass@2.0.0-beta install C:\node\test\node_modules\node-sass
> node scripts/install.js


module.js:340
    throw err;
          ^
Error: Cannot find module 'C:\scripts\install.js'
    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:929:3

npm ERR! node-sass@2.0.0-beta install: `node scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the node-sass@2.0.0-beta install script.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/install.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls node-sass
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nod
ejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "node-sass"
npm ERR! cwd C:\node\test
npm ERR! node -v v0.10.35
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0

一位同事向我发送了他的
install.js
文件,我把它放在我的根目录下,看看会发生什么。不幸的是,一旦npm尝试安装根模块所需的模块,安装仍然失败。

我想知道是否设置了“prefix”配置变量。你可以通过跑步找到答案

> npm c get prefix
> npm c get globalconfig
> npm c get localconfig
应将其设置为适用于全球套餐的合理值;如果设置为“C:\”,则可能导致您的问题

您可以通过运行

> npm c get prefix
> npm c get globalconfig
> npm c get localconfig
您可以列出所有配置变量

> npm c ls -l

我在尝试将node sass安装到Windows系统时遇到了类似的问题。我将此报告为节点sass问题(请参阅)

我在本地安装的节点中添加了一些额外的日志记录,以查看实际情况,并发现以下内容:

nodejs\node\u modules\npm\lib\utils\spawn.js用于启动scripts\install.js 通过添加一些额外的日志记录,我发现spawn.js正在使用以下命令行启动install.js:
C:\WINDOWS\system32\cmd.exe/C node scripts/install.js

在一个单独的命令提示符窗口中,我切换到我的c:\test目录,并运行
c:\WINDOWS\system32\cmd.exe/c节点
,查看哪个目录节点正在使用

在node>提示符下,我运行了
process.cwd()
。这将显示:
c:\\
而不是
c:\\test

当我看到上面的
c:\\
时,我记得我在Windows注册表中的
HKEY\U CURRENT\U USER\Software\Microsoft\Command Processor
中添加了自动运行设置,以便在每次启动cmd.exe时自动运行启动脚本。当我查看我的启动脚本时,我注意到该脚本中的最后一个命令是:
cdc:\
。这导致cmd.exe的每个实例都使用c:\作为其起始目录

从我的启动脚本中删除
cd c:\
后,npm安装节点sass正确运行


我希望这对遇到上述问题的其他人有所帮助。

您是否有
.npmrc
文件?如果是,请提供:)@AlexFord我以前没有听说过
.npmrc
文件,只是开始查找它们。谢谢你的提示!哪一个最有价值?如果你没有,那就无关紧要了。它只是NPM的配置文件。不过,我对Windows上的节点已经不太熟悉了:/Hmm我刚刚试过这个。看起来我的前缀是正确的,因为它返回的是
C:\Users\jamesm\AppData\Roaming\npm
。请尝试查看
npm C ls-l的输出,然后查看是否有不合理的设置为
C:`。另一种可能性-虽然如果不是你自己创建的,它不太可能,但可能是每个项目都有一个
.npmrc`某个地方,把事情搞砸了。去试试这个吧!谢谢你的信息。