我正在尝试使用 Vagrant 在 Virtualbox 计算机上设置开发环境。我使用 Windows 10 作为主机,使用 ubuntu/bionic64 作为访客机。
我的
package.json
文件位于主机和来宾计算机之间的共享目录下。但是,每当我运行 npm install --no-bin-links
时,我都会收到以下错误:
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vagrant/www/wp-content/plugins/my-plugin/node_modules/array-initial/node_modules/is-number/package.json.1640612897
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/www/wp-content/plugins/my-plugin/node_modules/array-initial/node_modules/is-number
/package.json.1640612897'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2021-01-19T05_31_47_272Z-debug.log
在访客计算机内,如果我将
package.json
和 package-lock.json
复制到另一个未共享的目录中,然后运行 npm install
一切正常。
mkdir /tmp/test/
cp package.json package-lock.json /tmp/test/
cd /tmp/test/ && npm install
# NPM Packages are installed successfully!
我认为这个错误是 Windows 特有的,因为我多年来一直是 Ubuntu 用户,从未遇到过类似的问题。我一周前才开始使用 Windows。
奇怪的是,我在同一台机器上还有另一个开发环境,NPM 工作得很好,共享文件夹没有任何问题!
我使用了
--no-bin-links
,所以我认为这个问题与符号链接没有任何关系。
查看
strace
输出,我看不到此文件 node_modules/array-initial/node_modules/is-number /package.json.1640612897
何时创建。
您需要启用符号链接:
VBoxManage setextradata YOUR_VM_NAME VBoxInternal2/SharedFoldersEnableSymlinksCreate/YOUR_SHARED_FOLDER_NAME 1
然后重新启动您的虚拟机。
请参阅 https://www.virtualbox.org/ticket/10085#comment:12 了解更多信息。