在Windows主机和Linux客户机上使用Vagrant时,尝试运行作业时, grunt
返回以下错误。
据我所知,这个文件path超过了主机客户共享目录上的Windows的255个字符的限制。
npm ERR! Error: EPERM, open '/u01/aa/bb/build/share/app-core/app- ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin- wrapper/node_modules/download/node_modules/request/node_modules/form- data/node_modules/combined-stream/test/integration/test-delayed-streams-and-buffers- and-strings.js'
我可以在客户虚拟机上的非共享目录上开发,但我更喜欢使用共享目录,因为我在主机上使用了IDE。
我怎样才能解决这个问题,以便我可以在共享目录上运行grunt
?
在角度发生器运行时,我遇到了类似的问题。 我现在找到的解决方案是利用npm处理依赖关系和文件夹结构的方式 。
请考虑您遇到的问题可能只影响几个文件(可能只有imagemin模块)。
对于Yeoman,我的解决方案是首先生成,跳过自动启动的安装:
yo angular appname --skip-install
手动启动凉亭安装:
bower install
从这里开始,应该会让你感兴趣:安装“request”npm模块作为第一级模块(而不是以后深入解决的依赖关系):
npm install request --save-dev
因此,如果您现在运行常规npm install来获取其余模块,则使用已经存在的请求模块。
npm install --no-bin-links
请注意,如果您不想以管理员身份运行VirtualBox,则使用--no-bin-links
也是一个好主意。
所以,要回答你的问题。 如果你正确地设置了你的软件包并且之前调用了npm install,运行grunt应该可以正常工作 模块“请求”是一个任意的模块,用于阻止test-delayed-streams-and-buffers-and-strings.js
文件的大路径。
如果使用默认的vboxsf
同步文件夹类型,则可以考虑使用新的基于rsync的同步文件夹来解决该问题。
rsync
类型将监视主机和来宾之间的文件夹,复制文件目录以使其保持同步。
默认vboxsf
和rsync
的区别在于后者会导致来宾Linux从本机文件系统(例如ext4
)而不是vboxsf
(由VirtualBox Guest Additions提供,在所有文件都是在Windows上)。
rsync
同步文件夹基本上使用rsync
CLI实用程序在主机之间复制/同步文件和目录。 所以一共有两份 在guest虚拟机中针对文件系统运行grunt
,它是本地Linux文件系统,不应受长路径影响(但ext4的最大文件名长度为255字节)。
默认情况下,流浪只会同步vagrant up
上的vagrant up
或vagrant reload
的文件夹。 但你可以运行vagrant rsync
手动强制同步或vagrant rsync-auto
来实时监控变化和同步。
参考: http : //docs.vagrantup.com/v2/synced-folders/rsync.html
您可以在下面的Vagrantfile
中将同步的文件夹类型设置为rsync
Vagrant.configure("2") do |config| config.vm.synced_folder ".", "/vagrant", type: "rsync", rsync__exclude: ".git/" end
更新
经过测试,创建目录树结构和文件,从Linux的角度来看没有问题,文件系统是ext4。 我怀疑这是npm的问题。
terry@arch:/$ uname -a Linux arch.apac.lab 3.14.1-1-ARCH #1 SMP PREEMPT Mon Apr 14 20:40:47 CEST 2014 x86_64 GNU/Linux terry@arch:/$ cat /u01/aa/bb/build/share/app-core/app-ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration/test-delayed-streams-and-buffers-and-strings.js test
更新 – rsync同步文件夹测试
我在一个物理Linux安装上做了以前的测试。 以下是在Mac上的快速测试,客人是一样的上面。
rsync同步文件夹配置
config.vm.synced_folder ".", "/u01/aa/bb/build/share/app-core/app-ui/ node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin- wrapper/node_modules/download/node_modules/request/node_modules/form-data/ node_modules/combined-stream/test/integration", type: "rsync
注意:我
chown -R vagrant:vagrant /u01/
递归地事先避免同步时的权限问题。
同步在vagrant up
$ vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Clearing any previously set forwarded ports... ==> default: Clearing any previously set network interfaces... ==> default: Preparing network interfaces based on configuration... default: Adapter 1: nat ==> default: Forwarding ports... default: 22 => 2222 (adapter 1) ==> default: Running 'pre-boot' VM customizations... ==> default: Booting VM... ==> default: Waiting for machine to boot. This may take a few minutes... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... default: Warning: Connection timeout. Retrying... ==> default: Machine booted and ready! ==> default: Checking for guest additions in VM... ==> default: Rsyncing folder: /ops/arch64/ => /u01/aa/bb/build/share/app-core/app-ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration ==> default: Mounting shared folders... default: /vagrant => /ops/arch64 ==> default: VM already provisioned. Run `vagrant provision` or use `--provision` to force it $ vagrant ssh Last login: Sun Apr 27 10:36:10 2014 from 10.0.2.2 vagrant@archlinux:~$ cd /u01/aa/bb/build/share/app-core/app-ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration vagrant@archlinux:/u01/aa/bb/build/share/app-core/app-ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration$ ls -l total 12 -rw-r----- 1 vagrant vagrant 14 Apr 27 10:35 test-delayed-streams-and-buffers-and-strings.js -rw-r----- 1 vagrant vagrant 5018 Apr 27 10:22 Vagrantfile vagrant@archlinux:/u01/aa/bb/build/share/app-core/app-ui/node_modules/grunt-contrib-imagemin/node_modules/pngquant-bin/node_modules/bin-wrapper/node_modules/download/node_modules/request/node_modules/form-data/node_modules/combined-stream/test/integration$ cat test-delayed-streams-and-buffers-and-strings.js stackoverflow
结果是一样的。 如前所述,我怀疑这可能是一个NPM问题。
对于这个实际的解决方案,看看这个评论 ,或继续阅读这里:
config.vm.provider "virtualbox" do |v| v.customize ["sharedfolder", "add", :id, "--name", "www", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/www").gsub("/","\\"))] end config.vm.provision :shell, inline: "mkdir /home/vagrant/www" config.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` www /home/vagrant/www", run: "always"
在上面的代码中,我将\\?\附加到当前目录的绝对路径。 这实际上会强制Windows API允许增加MAX_PATH变量(通常限制在260)。 了解更多关于最大路径 。 这是在共享文件夹的创建过程中发生的,而VBoxManage并不是Vagrant的“synced_folder”方法。 最后一点是不言自明的; 我们创建新的共享文件夹,然后确保每次访问或触摸机器时都会安装它,因为Vagrant喜欢在每个负载上重新加载其安装/共享文件夹。
我希望这有帮助!