在 Windows 共享上安装软件包时出现 Npm 错误

F21*_*F21 53 permissions cifs shared-folders windows-8 npm

我在 Windows 8 主机上以 VMware 来宾身份运行 Ubuntu 12.10。

我在我的 Windows 8 主机上共享了一个文件夹,它在启动时使用以下条目安装在 Ubuntu 来宾中fstab

//myhost/work /work cifs credentials=/home/user/.smbcredentials,noserverino,nounix,uid=user,gid=user,file_mode=0777,dir_mode=0777 0 0 
Run Code Online (Sandbox Code Playgroud)

该共享工作正常,并且能够由诸如 nginx 之类的网络服务器提供服务。

但是,当我使用 npm 安装 node.js 包时似乎有问题,我收到了一堆这样的错误:

user@ubuntu:/work/test$ sudo npm install grunt
npm http GET https://registry.npmjs.org/grunt
npm http 304 https://registry.npmjs.org/grunt
...
npm ERR! error rolling back Error: ENOTEMPTY, rmdir '/work/test/node_modules/grunt/node_modules/lodash'
npm ERR! error rolling back  grunt@0.4.1 { [Error: ENOTEMPTY, rmdir '/work/test/node_modules/grunt/node_modules/lodash']
npm ERR! error rolling back   errno: 53,
npm ERR! error rolling back   code: 'ENOTEMPTY',
npm ERR! error rolling back   path: '/work/test/node_modules/grunt/node_modules/lodash' }
npm ERR! Error: UNKNOWN, symlink '../which/bin/which'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.5.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "grunt"
npm ERR! cwd /work/test
npm ERR! node -v v0.10.0
npm ERR! npm -v 1.2.14
npm ERR! path ../which/bin/which
npm ERR! code UNKNOWN
npm ERR! errno -1
npm ERR! Error: ENOENT, chmod '/work/test/node_modules/grunt/node_modules/findup-sync/test/fixtures/aaa.txt'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.5.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "grunt"
npm ERR! cwd /work/test
npm ERR! node -v v0.10.0
npm ERR! npm -v 1.2.14
npm ERR! path /work/test/node_modules/grunt/node_modules/findup-sync/test/fixtures/aaa.txt
npm ERR! fstream_path /work/test/node_modules/grunt/node_modules/findup-sync/test/fixtures/aaa.txt
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! fstream_finish_call chmod
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/writer.js:305:19
npm ERR! fstream_stack Object.oncomplete (fs.js:93:15)
npm ERR! Error: ENOENT, lstat '/work/test/node_modules/grunt/node_modules/minimatch/test/basic.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 3.5.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "grunt"
npm ERR! cwd /work/test
npm ERR! node -v v0.10.0
npm ERR! npm -v 1.2.14
npm ERR! path /work/test/node_modules/grunt/node_modules/minimatch/test/basic.js
npm ERR! fstream_path /work/test/node_modules/grunt/node_modules/minimatch/test/basic.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code ENOENT
npm ERR! errno 34
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:93:15)
npm ERR! Error: ENOENT, lstat '/work/test/node_modules/grunt/node_modules/glob/test/00-setup.js'
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>
...
npm ERR! not ok code 0
user@ubuntu:/work/test$ 
Run Code Online (Sandbox Code Playgroud)

什么可能导致这个问题?在命令行,我能chmodrmdir其中使用sudo没有任何问题的其他事情。

F21*_*F21 121

运行--no-bin-links为我修复了它:

npm install --no-bin-links
Run Code Online (Sandbox Code Playgroud)

--no-bin-links告诉npm不要创建任何符号链接。没有办法(据我所知)将符号链接转换为 Windows 共享。

  • 我希望我能再给你 200 次投票。这使得在 Windows 上使用 Vagrant 成为可能。 (16认同)
  • 很好的答案!但是有没有办法使用 Grunt 的 package.json 文件的“devDependencies”来完成这项工作?那将是真棒 :) (2认同)

小智 6

如何允许在 Windows 上创建符号链接此页面对我有很大帮助,这解释了即使您的共享文件夹可写也会发生这种情况。

要修复它,您需要在 VirtualBox 中启用符号链接功能。

在 cmd 提示符下运行:

VBoxManage setextradata YOURVMNAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/YOURSHAREFOLDERNAME 1
Run Code Online (Sandbox Code Playgroud)

然后通过以下方式验证:

VBoxManage getextradata YOURVMNAME enumerate
Run Code Online (Sandbox Code Playgroud)

如果您的用户属于管理员组,则以“以管理员身份运行”启动 VirtualBox!

默认情况下,Windows 7 安全策略不允许创建符号链接,因为它是潜在的安全威胁。运行“secpol.msc”并导航到“本地策略-用户权限分配”并将您的用户添加到“创建符号链接”。我没有尝试过,但可能是在虚拟机可以作为普通用户运行之后。