EDIT: See updated section below, where I modified the Code according to given solution suggestions
编辑:请参阅下面的更新部分,我根据给定的解决方案建议修改了代码
I am using vagrant with homestead on my win7 machine. And I want to install some gulp packages for example gulp-uncss, which does not work because I get the error added below.
我在win7机器上使用vagtead和宅基地。我想安装一些gulp软件包,例如gulp-uncss,这不起作用,因为我收到下面添加的错误。
After some research and discussions in the #npm IRC channel I was hinted to this problem here:
经过#npm IRC频道的一些研究和讨论后,我在这里暗示了这个问题:
According to this entry, windows users still have a problem when using vagrant, because the shared folder between host and guest machine has the max-character limitation of 260 characters, which has always been a major issue with windows development.
根据此条目,Windows用户在使用vagrant时仍然存在问题,因为主机和客户机之间的共享文件夹具有260个字符的最大字符限制,这一直是Windows开发的主要问题。
A solution seems to be to change the vagrant file and the provisions along with it.
一个解决方案似乎是改变流浪文件和规定。
Here is the initial error:
这是最初的错误:
vagrant@homestead:~/Code/Wordpress/wp-content/themes/expimo$ gulp uncss
[10:51:07~/Code/Wordpress/wp-content/themes/expimo/gulpfile.js
[10:51:07] Starting 'uncss'...
/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/bluebird/js/main/async.js:43
fn = function () { throw arg; };
^
TypeError: Bad argument
at TypeError (native)
at ChildProcess.spawn (child_process.js:1136:26)
at /home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/lib/spawn.js:82:38
at init (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePro
at new Promise (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:27:53)
at Function.promise (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/when.js:97:10)
at startPhantom (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/lib/spawn.js:58:25)
at tryCatchReject (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:845:30)
at runContinuation1 (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:804:4)
at Fulfilled.when (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:592:4)
at Pending.run (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/makePromise.js:483:13)
at Scheduler._drain (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/Scheduler.js:62:19)
at Scheduler.drain (/home/vagrant/Code/Wordpress/wp-content/themes/expimo/node_modules/gulp-uncss/node_modules/uncss/node_modules/phridge/node_modules/when/lib/Scheduler.js:27:9)
at process._tickCallback (node.js:355:11)
As I have understood from the entry, is that I have to modify my Vagrantfile and maybe even add some provisions?
正如我从条目中理解的那样,我是否必须修改我的Vagrantfile,甚至可能添加一些条款?
This is my the current default Vagrantfile added through homestead:
这是我通过宅基地添加的当前默认Vagrantfile:
require 'json'
require 'yaml'
VAGRANTFILE_API_VERSION = "2"
homesteadYamlPath = File.expand_path("~/.homestead/Homestead.yaml")
afterScriptPath = File.expand_path("~/.homestead/after.sh")
aliasesPath = File.expand_path("~/.homestead/aliases")
require_relative 'scripts/homestead.rb'
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exists? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
Homestead.configure(config, YAML::load(File.read(homesteadYamlPath)))
if File.exists? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath
end
end
And apparently I have to insert the modifications stated here: https://github.com/renobit/vagrant-node-env/commit/bdf15f2f301e2b1660b839875e34f172ea8be227
显然我必须插入此处所述的修改:https://github.com/renobit/vagrant-node-env/commit/bdf15f2f301e2b1660b839875e34f172ea8be227
inside this Vagrantfile, so that homestead works properly windows.
在这个Vagrantfile里面,这样宅基地可以正常工作。
Since I just started using vagrant, my knowledge is very limited, therefore I would welcome any help I can get on this topic. Thank you in advance.
由于我刚开始使用流浪汉,我的知识非常有限,因此我欢迎任何有关此主题的帮助。先感谢您。
UPDATE
UPDATE to David Myers suggestion:
更新大卫迈尔斯的建议:
I modified my Vagrantfile according to David Myers suggestion below to no avail:
我根据David Myers的建议修改了我的Vagrantfile,但无济于事:
require 'json'
require 'yaml'
VAGRANTFILE_API_VERSION = "2"
confDir = $confDir ||= File.expand_path("~/.homestead")
homesteadYamlPath = confDir + "/Homestead.yaml"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"
require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
if File.exists? aliasesPath then
config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
end
# this should be inserted right before the "Homestead.configure()" line
config.vm.provider "virtualbox" do |v, override|
if Vagrant::Util::Platform.windows?
override.vm.synced_folder "./Code", "/home/vagrant/Code", disabled: true
v.customize ["sharedfolder", "add", :id, "--name", "Code", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/Code").gsub("/","\\"))]
override.vm.provision :shell, inline: "mkdir -p /home/vagrant/Code"
override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` Code /home/vagrant/Code", run: "always"
else
override.vm.synced_folder "./Code", "/home/vagrant/Code"
end
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Code", "1"]
end
# this should be inserted right before the "Homestead.configure()" line
Homestead.configure(config, YAML::load(File.read(homesteadYamlPath)))
if File.exists? afterScriptPath then
config.vm.provision "shell", path: afterScriptPath
end
end
And I also commented out the three lines you pointed out in my Homestead.yaml file:
我还注释了你在Homestead.yaml文件中指出的三行:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
# folders:
# - map: ~/Code
# to: /home/vagrant/Code
sites:
- map: expimo.app
to: /home/vagrant/Code/Wordpress
- map: laravel.app
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
Unfortunately then I get the Error Message:
不幸的是我得到错误信息:
No input file specified, because it seems the URIs are not directed to the right folder.
没有指定输入文件,因为似乎URI未定向到正确的文件夹。
If I then just uncomment the three lines again in my homestead.yaml file, and keep the modified Vagrantfile, I get the same error, when I am trying to install gulp-uncss through "npm install gulp-uncss --save-dev".
如果我然后在我的homestead.yaml文件中再次取消注释这三行,并保留修改后的Vagrantfile,我得到相同的错误,当我尝试通过“npm install gulp-uncss --save-dev”安装gulp-uncss时。
What should I do next?
接下来我该怎么办?
2 个解决方案
#1
I'm the one who implemented that fix you mentioned. :)
我是那个实施你提到的修复的人。 :)
I personally haven't run into this issue with Homestead yet, but I think I know what you need to do. First, you will need to comment out these lines in the Homestead.yaml
file:
我个人还没有遇到过Homestead这个问题,但我想我知道你需要做什么。首先,您需要在Homestead.yaml文件中注释掉这些行:
folders
- map: ~/Code
to: /home/vagrant/Code
Next, you'll need to add this configuration to your Vagrantfile
:
接下来,您需要将此配置添加到您的Vagrantfile:
# this should be inserted right before the "Homestead.configure()" line
config.vm.provider "virtualbox" do |v, override|
if Vagrant::Util::Platform.windows?
override.vm.synced_folder "./Code", "/home/vagrant/Code", disabled: true
v.customize ["sharedfolder", "add", :id, "--name", "Code", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/Code").gsub("/","\\"))]
override.vm.provision :shell, inline: "mkdir -p /home/vagrant/Code"
override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` Code /home/vagrant/Code", run: "always"
else
override.vm.synced_folder "./Code", "/home/vagrant/Code"
end
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Code", "1"]
end
# this should be inserted right before the "Homestead.configure()" line
Note the comments in the previous block; you need to make sure it is inserted before the Homestead configuration is run.
注意上一个块中的注释;您需要确保在运行Homestead配置之前插入它。
NOTE: This script assumes you are sharing a directory called "Code" that is located in the same directory as this Vagrantfile.
注意:此脚本假定您正在共享一个名为“Code”的目录,该目录与此Vagrantfile位于同一目录中。
#2
I put up a full guide/walkthrough for Homestead on Windows that addresses all these issues (and others, like caching problems with winnfsd/etc) and solutions for Laravel 5 & Lumen. I will be keeping this Gist up-to-date (and continually improve it's readability). You can find the Gist here: https://gist.github.com/prograhammer/9493ee04f30dd74e121b
我为Windows上的Homestead提供了一个完整的指南/演练,解决了所有这些问题(以及其他问题,例如winnfsd /等的缓存问题)以及Laravel 5和Lumen的解决方案。我将保持这个Gist最新(并不断提高它的可读性)。你可以在这里找到要点:https://gist.github.com/prograhammer/9493ee04f30dd74e121b
In that Gist, I had to add a few steps to David Myers solution:
在那个Gist中,我不得不向David Myers解决方案添加几个步骤:
Update C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\plugins\providers\virtualbox\driver\version_4_3.rb
somewhere near lines 495-510, replace the line folder[:hostpath]
with '\\\\?\\' + folder[:hostpath].gsub(/[\/\\]/,'\\')]
在第495-510行附近的某处更新C:\ HashiCorp \ Vagrant \ embedded \ gems \ gems \ vagrant-1.7.2 \ plugins \ providers \ virtualbox \ driver \ version_4_3.rb,将行文件夹[:hostpath]替换为'\\ \\?\\'+ folder [:hostpath] .gsub(/ [\ / \\] /,'\\')]
Update C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\lib\vagrant\util\platform.rb
and comment out a big part of this section:
更新C:\ HashiCorp \ Vagrant \ embedded \ gems \ gems \ vagrant-1.7.2 \ lib \ vagrant \ util \ platform.rb并注释掉本节的大部分内容:
# This expands the path and ensures proper casing of each part
# of the path.
def fs_real_path(path, **opts)
#path = Pathname.new(File.expand_path(path))
#
# if path.exist? && !fs_case_sensitive?
# # Build up all the parts of the path
# original = []
# while !path.root?
# original.unshift(path.basename.to_s)
# path = path.parent
# end
#
# # Traverse each part and join it into the resulting path
# original.each do |single|
# Dir.entries(path).each do |entry|
# if entry.downcase == single.encode('filesystem').downcase
# path = path.join(entry)
# end
# end
# end
#end
#
# if windows?
# # Fix the drive letter to be uppercase.
# path = path.to_s
# if path[1] == ":"
# path[0] = path[0].upcase
# end
#
# path = Pathname.new(path)
#end
path
end
Now vagrant up.
现在流浪了。
#1
I'm the one who implemented that fix you mentioned. :)
我是那个实施你提到的修复的人。 :)
I personally haven't run into this issue with Homestead yet, but I think I know what you need to do. First, you will need to comment out these lines in the Homestead.yaml
file:
我个人还没有遇到过Homestead这个问题,但我想我知道你需要做什么。首先,您需要在Homestead.yaml文件中注释掉这些行:
folders
- map: ~/Code
to: /home/vagrant/Code
Next, you'll need to add this configuration to your Vagrantfile
:
接下来,您需要将此配置添加到您的Vagrantfile:
# this should be inserted right before the "Homestead.configure()" line
config.vm.provider "virtualbox" do |v, override|
if Vagrant::Util::Platform.windows?
override.vm.synced_folder "./Code", "/home/vagrant/Code", disabled: true
v.customize ["sharedfolder", "add", :id, "--name", "Code", "--hostpath", (("//?/" + File.dirname(__FILE__) + "/Code").gsub("/","\\"))]
override.vm.provision :shell, inline: "mkdir -p /home/vagrant/Code"
override.vm.provision :shell, inline: "mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` Code /home/vagrant/Code", run: "always"
else
override.vm.synced_folder "./Code", "/home/vagrant/Code"
end
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/Code", "1"]
end
# this should be inserted right before the "Homestead.configure()" line
Note the comments in the previous block; you need to make sure it is inserted before the Homestead configuration is run.
注意上一个块中的注释;您需要确保在运行Homestead配置之前插入它。
NOTE: This script assumes you are sharing a directory called "Code" that is located in the same directory as this Vagrantfile.
注意:此脚本假定您正在共享一个名为“Code”的目录,该目录与此Vagrantfile位于同一目录中。
#2
I put up a full guide/walkthrough for Homestead on Windows that addresses all these issues (and others, like caching problems with winnfsd/etc) and solutions for Laravel 5 & Lumen. I will be keeping this Gist up-to-date (and continually improve it's readability). You can find the Gist here: https://gist.github.com/prograhammer/9493ee04f30dd74e121b
我为Windows上的Homestead提供了一个完整的指南/演练,解决了所有这些问题(以及其他问题,例如winnfsd /等的缓存问题)以及Laravel 5和Lumen的解决方案。我将保持这个Gist最新(并不断提高它的可读性)。你可以在这里找到要点:https://gist.github.com/prograhammer/9493ee04f30dd74e121b
In that Gist, I had to add a few steps to David Myers solution:
在那个Gist中,我不得不向David Myers解决方案添加几个步骤:
Update C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\plugins\providers\virtualbox\driver\version_4_3.rb
somewhere near lines 495-510, replace the line folder[:hostpath]
with '\\\\?\\' + folder[:hostpath].gsub(/[\/\\]/,'\\')]
在第495-510行附近的某处更新C:\ HashiCorp \ Vagrant \ embedded \ gems \ gems \ vagrant-1.7.2 \ plugins \ providers \ virtualbox \ driver \ version_4_3.rb,将行文件夹[:hostpath]替换为'\\ \\?\\'+ folder [:hostpath] .gsub(/ [\ / \\] /,'\\')]
Update C:\HashiCorp\Vagrant\embedded\gems\gems\vagrant-1.7.2\lib\vagrant\util\platform.rb
and comment out a big part of this section:
更新C:\ HashiCorp \ Vagrant \ embedded \ gems \ gems \ vagrant-1.7.2 \ lib \ vagrant \ util \ platform.rb并注释掉本节的大部分内容:
# This expands the path and ensures proper casing of each part
# of the path.
def fs_real_path(path, **opts)
#path = Pathname.new(File.expand_path(path))
#
# if path.exist? && !fs_case_sensitive?
# # Build up all the parts of the path
# original = []
# while !path.root?
# original.unshift(path.basename.to_s)
# path = path.parent
# end
#
# # Traverse each part and join it into the resulting path
# original.each do |single|
# Dir.entries(path).each do |entry|
# if entry.downcase == single.encode('filesystem').downcase
# path = path.join(entry)
# end
# end
# end
#end
#
# if windows?
# # Fix the drive letter to be uppercase.
# path = path.to_s
# if path[1] == ":"
# path[0] = path[0].upcase
# end
#
# path = Pathname.new(path)
#end
path
end
Now vagrant up.
现在流浪了。