使用 vagrant up 时出现 vagrant 问题

Issue with vagrant while using vagrant up

在安装新的 vagrant 实例时,我在使用 vagrant up 时遇到此错误。这是错误

Vagrant failed to initialize at a very early stage:

There is a syntax error in the following Vagrantfile. The syntax error
message is reproduced below for convenience:

/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:141: syntax error, unexpected tPOW
...ype: folder["type"] ||= nil, **options
...                               ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:157: syntax error, unexpected keyword_do_block, expecting keyword_end
      settings["sites"].each do |site|
                               ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:207: syntax error, unexpected keyword_do_block, expecting keyword_end
        settings["databases"].each do |db|
                                     ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:208: syntax error, unexpected tSTRING_BEG, expecting keyword_end
          config.vm.provision "shell" do |s|
                               ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:208: syntax error, unexpected keyword_do_block, expecting keyword_end
          config.vm.provision "shell" do |s|
                                        ^
/mnt/c/Users/bilal/Homestead/scripts/homestead.rb:220: syntax error, unexpected keyword_end, expecting $end

这是我的 VagrantFile 内容

# -*- mode: ruby -*-
# vi: set ft=ruby :

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION ||= "2"
confDir = $confDir ||= File.expand_path("~/.homestead")

homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"

require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')

Vagrant.require_version '>= 1.8.4'

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    if File.exist? aliasesPath then
        config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
    end

    if File.exist? homesteadYamlPath then
        settings = YAML::load(File.read(homesteadYamlPath))
    elsif File.exist? homesteadJsonPath then
        settings = JSON.parse(File.read(homesteadJsonPath))
    end

    Homestead.configure(config, settings)

    if File.exist? afterScriptPath then
        config.vm.provision "shell", path: afterScriptPath, privileged: false
    end

    if defined? VagrantPlugins::HostsUpdater
        config.hostsupdater.aliases = settings['sites'].map { |site| site['map'] }
    end
end

============================================= ===============

还有 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: /mnt/e/XAMPP/htdocs

sites:
    - map: homestead.app
      to: /mnt/e/XAMPP/htdocs/cap/web

databases:
    - homestead

通过将 Vagrant 升级到 1.8.4 解决了该问题。