npm 总是使用主目录作为当前工作目录 [英] npm always using home directory as current working directory

查看:62
本文介绍了npm 总是使用主目录作为当前工作目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

npm 坚持使用我的主目录作为当前工作目录,无论我从哪个目录执行命令.

npm insists on using my home directory as the current working directory, no matter which directory I am executing commands from.

cmd 和 Powershell 都发生了,我尝试删除和重新安装节点,都使用 nodejs.org 上的安装程序,并通过 巧克力具有相同的结果.

Happens with both cmd and Powershell, I've tried removing and reinstalling node, both using the installer on nodejs.org, and via Chocolatey with the same result.

如果我导航到例如C:\test 并运行 npm init,向导将生成的 package.json 文件放在我的主文件夹中.

If I navigate to e.g. C:\test and run npm init, the wizard places the resulting package.json file in my home folder.

如果我从任何文件夹运行 npm install ,该软件包将安装到 C:\Users\myusername\node_modules

If I run npm install <package> from any folder, the package is installed to C:\Users\myusername\node_modules

尝试全局安装软件包也会失败,原因是

Trying to install a package globally also fails, with this

npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\ProgramData\\chocolatey\\lib\\nodejs.commandline.0.10.33\\tools\\node.exe" "C:\\ProgramData\\chocolatey\\lib\\npm.1.4.9\\tools\\node_modules\\npm\\bin\\npm-cli.js" "install" "gulp" "-g"
npm ERR! cwd C:\Users\<myusername>

如果我导航到一个文件夹,启动节点 REPL 并运行 process.cwd() 返回我启动节点的目录,所以问题似乎仅限于 npm.

If I navigate to a folder, start the node REPL and run process.cwd() the directory I started node from is returned, so the issue seems to be limited to npm.

运行 npm get 得到这个结果:

Running npm get gives this result:

C:\test> npm get
; cli configs
registry = "https://registry.npmjs.org/"
user-agent = "npm/1.4.9 node/v0.10.33 win32 x64"

; node bin location = C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.33\tools\node.exe
; cwd = C:\Users\<myusername>
; HOME = C:\Users\<myusername>
; 'npm config ls -l' to show all defaults.

我搜索了很多解决方案,并找到了一些类似 问题a>,但没有解决我的问题.我知道 npm 会沿着目录树向上查找 node_modules 文件夹,但这也发生在我的主目录之外的文件夹中.

I've searched quite a bit for a solution, and have found some similar issues, but none that solved my problem. I know that npm walks up the directory tree to look for a node_modules folder, but this happens in folders outside my home directory as well.

关于我尝试解决此问题的任何提示?

Any tips on what I try to resolve this?

推荐答案

原来我在 HKEY_LOCAL_MACHINE\Software\Microsoft\ 中有一个 cd C:\Users\ 命令命令 Processor\AutoRun 在注册表中.这意味着该命令在 CMD.EXE 启动时随时执行.

Turns out I had a cd C:\Users\<myusername> command in HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun in the registry. Meaning that this command was executed any time CMD.EXE started.

不知道它是怎么进来的,我可能在某个时候自己添加了它.

No idea how that got in there, I might have added it myself at some point.

无论如何,如果有人在执行脚本时和在打开的命令提示符下手动运行相同命令时遇到当前工作目录之间的差异,HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRunHKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun是检查的好地方.

Anyway, if someone experiences differences between the current working directory when executing a script and when running the same command manually in an open command prompt, HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRunare good places to check.

这篇关于npm 总是使用主目录作为当前工作目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆