使用 NVM 时,无法全局安装 npm 包

when using NVM, unable to install npm packages globally

我在 windows 中使用 NVM,它基本上通过更改它在 "C:\program files\nodejs"

中创建的快捷方式在 nodeJs 的版本之间切换

当我

nvm use 7.0

然后快捷方式更新为"c:\users\me\AppData\Roaming\nvm\v7.0"

如果我用4.6,那么"c:\users\me\AppData\Roaming\nvm\v4.6"

因为实际的节点文件位于 NVM 文件夹中...

"C:\program files\nodejs"里面的所有文件都被锁定了,因为这个,当我运行

npm install -g package

,作为安装过程的一部分,它尝试重命名一些 files/directories,但它不能,但失败了....

-info using npm@3.10.8
-info using node@v7.0.0
-error Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\@angular\cli' -> 'C:\Program Files\nodejs\node_modules\@angular\.cli.DELETE'
-error  Error
-error     at moveAway (C:\Users\me\AppData\Roaming\nvm\v7.0.0\node_modules\npm\lib\install\action\finalize.js:38:5)
-error     at destStatted (C:\Users\me\AppData\Roaming\nvm\v7.0.0\node_modules\npm\lib\install\action\finalize.js:27:7)
-error     at FSReqWrap.oncomplete (fs.js:111:15)
-error
-error Error: EPERM: operation not permitted, rename 'C:\Program Files\nodejs\node_modules\@angular\cli' -> 'C:\Program Files\nodejs\node_modules\@angular\.cli.DELETE'
-error Please try running this command again as root/Administrator.
-verbose exit [ -4048, true ]

在 NVM 之前我可以全局安装包,现在不能了。 我尝试解锁 "program files\nodejs\node_modules" 没有错误,但目录仍然锁定。

解锁可能不是正确的方法,因为每当我们切换到其他节点版本时,它都会再次被锁定。

我没有管理员权限,但我想这应该不是问题...

我认为问题出在管理员权限上。

作为解决方法,您可以在项目中安装包,并在 ./node_modules/.bin/ 文件夹中访问它的二进制文件。