环境:
- 微软 Windows 11
- 流浪盒:VirtualBox 通用/ubuntu2204
- “../gloss-translation” 是主机上的 repo 根目录。
Vagrant文件:
vb.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/~/gloss-translation", "1"]
config.vm.synced_folder "../gloss-translation", "/home/vagrant/gloss-translation"
# Root Provision section:
config.vm.provision "shell", name: "nodejs", inline: <<-SHELL
echo "Provisioning with root access"
# Update resynchronizes the package index files from their sources.
apt-get update
# *** Install Node.js 18 ***
echo "Installing Node.js 18..."
# 1. Download and import the Nodesource GPG key
sudo apt-get install -y ca-certificates curl gnupg
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
# 2. Create deb repository
NODE_MAJOR=18
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
# 3. Run Update and Install
sudo apt-get update
sudo apt-get install nodejs -y
echo "End of: Installing Node.js 18"
SHELL
# Vagrant Provision section:
config.vm.provision "shell", name: "npm", privileged: false, inline: <<-SHELL
cd /home/vagrant/gloss-translation
echo "Performing npm install..."
npm install
echo "Setting nx as global..."
npm i -g nx
echo "npm provisioning completed."
SHELL
标准输出错误消息:
vagrant@ubuntu2204:~/gloss-translation$ npm install
npm ERR! code ENOTSUP
npm ERR! syscall write
npm ERR! errno -95
npm ERR! ENOTSUP: operation not supported on socket, write
npm ERR! A complete log of this run can be found in: /home/vagrant/.npm/_logs/2023-10-03T14_08_28_991Z-debug-0.log
上述日志文件的摘录:
56 timing command:install Completed in 170ms
57 verbose stack Error: ENOTSUP: operation not supported on socket, write
58 verbose cwd /home/vagrant/gloss-translation
59 verbose Linux 5.15.0-84-generic
60 verbose node v18.18.0
61 verbose npm v9.8.1
62 error code ENOTSUP
63 error syscall write
64 error errno -95
65 error ENOTSUP: operation not supported on socket, write
66 verbose exit -95
67 timing npm Completed in 581ms
68 verbose unfinished npm timer reify 1696342109381
69 verbose unfinished npm timer reify:save 1696342109541
70 verbose code -95
71 error A complete log of this run can be found in: /home/vagrant/.npm/_logs/2023-10-03T14_08_28_991Z-debug-0.log
我迄今为止尝试过的:
- 运行此命令:VBoxManage.exe setextradata vagrant-project_default_1696285759671_47273 VBoxInternal2/SharedFoldersEnableSymlinksCreate/~/gloss-translation 1
- 授予使用本地安全策略创建到“经过身份验证的用户”的符号链接
- 删除项目根目录中的目录“node_modules”
- 在客户机中创建了一个目录 ~/node_modules;cd ~/gloss-translation;ln -s ~/node_modules;npm install
结果: 以上所有做法均失败了。
答案1
我可以通过更改此语句来解决问题:
config.vm.synced_folder "../gloss-translation", "/home/vagrant/gloss-translation"
有了这个:
config.vm.synced_folder "../gloss-translation", "/home/vagrant/gloss-translation", type: "rsync"
唯一的缺点是我需要发出:
vagrant rsync
为了同步文件夹或者您可以发出:
vagrant rsync-auto
让 vagrant 监视目录并在目录发生变化时发出 rsync 。