ruby 在OSX Mavericks之后,无法加载此类文件-- script/../config/ Boot (LoadError)

xdnvmnnf  于 2022-11-22  发布在  Ruby
关注(0)|答案(2)|浏览(173)

昨天我在一个ruby on rails应用程序(v2.3)上做开发,并决定将我的iMac更新到OSX Mavericks。现在,每次我试图在本地运行我的应用程序时,我都会得到以下错误。有人知道是什么导致了这个错误吗?

像这样奔跑

script/server -e development

错误:

/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- script/../config/boot (LoadError)
        from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
        from script/server:2:in `<main>'

脚本/服务器(文件)

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/server'

在安装OSX Mavericks之前,它工作正常。
我注意到的事情:

  • ruby的版本现在安装在2.0中(之前是v1.8.7)

FYI:我对Rails还是个新手。

安装RVM之后:

好的,我设置了RVM,并确保安装了ruby(1.8.7)和rails(2.3.11)的版本,并将其配置为默认版本。
已安装的RVM:

curl -L https://get.rvm.io | bash -s stable --rails

安装Ruby 1.8.7:

rvm install ruby-1.8.7-p374

将v1.8.7设置为默认版本:

rvm --default use 1.8.7

安装导轨v2.3.11:

gem install rails -v 2.3.11

从系统安装所有gem

rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system

现在,当我运行应用程序时,我收到以下错误:(我错过了什么?)

=> Booting WEBrick...
/Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require': no such file to load -- haml (MissingSourceFile)
    from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/plugins/haml/init.rb:5:in `evaluate_init_rb'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:95:in `evaluate_init_rb'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:11:in `silence_warnings'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:91:in `evaluate_init_rb'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin.rb:44:in `load'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:33:in `load_plugins'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `each'
    from ./script/../config/../vendor/rails/railties/lib/rails/plugin/loader.rb:32:in `load_plugins'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:292:in `load_plugins'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:142:in `process'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:97:in `send'
    from ./script/../config/../vendor/rails/railties/lib/initializer.rb:97:in `run'
    from /Users/imaginationplus/gitlocal/dfc_workshop/config/environment.rb:14
    from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require'
    from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/railties/lib/commands/servers/webrick.rb:59
    from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `gem_original_require'
    from /Users/imaginationplus/.rvm/rubies/ruby-1.8.7-p374/lib/ruby/site_ruby/1.8/rubygems/core_ext/kernel_require.rb:53:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:355:in `new_constants_in'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/activesupport/lib/active_support/dependencies.rb:510:in `require'
    from /Users/imaginationplus/gitlocal/dfc_workshop/vendor/rails/railties/lib/commands/server.rb:39
    from script/server:3:in `require'
    from script/server:3
ryoqjall

ryoqjall1#

从这个问题中要理解的主要事情是,你不能依赖于你的ruby版本的操作系统或者你在ruby项目中使用的gem。当你创建额外的ruby应用程序时,你可能会再次遇到这个问题。

-  To manage the gems use Bundler
   Bundler maintains a consistent environment for each ruby applications. 

-  To manage the Ruby versions use rbenv or rvm
r7xajy2e

r7xajy2e2#

ruby的版本现在安装在2.0中(之前是v1.8.7)
在Ruby的2.x版本中,当前目录在默认情况下不再位于$LOAD_PATH中,这意味着使用require来加载相对于当前目录的文件(例如script/../config/ Boot ,它扩展为config/boot)将不起作用。
备选方案包括:
1.编辑$LOAD_PATH以包括当前目录,例如$LOAD_PATH << "."
1.使用require_relative
找到上述解决方案here

相关问题