3

我的 Gemfile 似乎加载了两次。当我运行 bundle install 我看到...

宝石文件:

source 'http://rubygems.org'


gem 'haml'                    # asset engine
gem 'jquery-rails'
gem 'rails',                  '= 3.1.1'
gem 'readable_exceptions'
gem 'sass-rails',             "= 3.1.4"  # asset engine
gem 'uglifier'                # asset engine
gem 'bundler',                ">= 1.0.18" # 1.0.18 is required for proper asset pipeline support
gem "rake", "=0.8.7"
gem "resque"
gem 'date_validator'
gem "typhoeus"
gem 'newrelic_rpm'
gem "scout_rails"
puts "Loading Gemfile"

输出:

Loading Gemfile
Loading Gemfile
Using rake (0.8.7) 
Using multi_json (1.3.6) 
Using activesupport (3.1.1) 

我相信这会导致我的开发环境出现问题,其中所有内容都被加载了两次。当我使用乘客独立运行服务器时,我有奇怪的日志,例如:

开发日志:

/app/models/facebook_application.rb:47: warning: already initialized constant APP_PROPERTIES
/app/models/facebook_application.rb:59: warning: already initialized constant ADJUSTABLE_MIGRATIONS
/app/models/facebook_application.rb:210: warning: already initialized constant MAX_TRIES

什么样的系统问题会导致所有内容都被加载两次?

我是:

  • 使用 RVM
  • 我已删除所有系统红宝石宝石
  • 使用捆绑器
  • 我已删除 .rvmrc 文件
  • 不使用宝石
  • 使用 ruby​​-1.9.2-p320
  • 使用导轨 3.1.1
4

3 回答 3

2

也许我遗漏了一些东西,但看起来 gem 'scout-rails' 后面有一行写着 puts 'Loading Gemfile'

所以也许不是你要加载你的 Gemfile 两次(这实际上不会成为问题,因为我们可以捆绑安装一整天而不会损坏任何东西),但它看起来就像你的那样,因为你放了一条线说它。

于 2012-07-30T17:36:40.333 回答
0

这就是 Bundler 的工作方式。它执行一些检查以满足现有的依赖关系。BundlerGemfile在它自己的 DSL 中运行以获得依赖关系树。

Ruby 级别禁止双重要求:第一次require加载文件,下一次调用返回false表明该文件已经在聚会上,无需再次加载。所以我怀疑 Bundler 会导致你的错误。

顺便说一句,您不必使用bundle exec命令rails。Rails 核心团队成员在这里解释了原因。

顺便说一下 #2:install是 defaultbundle的行为。

于 2012-07-30T19:39:59.147 回答
0

我遇到了同样的问题,这是由于Dsl#eval_gemfile从以下位置被调用两次引起的:

  1. https://github.com/bundler/bundler/blob/67320924db1f1910b17fae0a9268b02077874d26/lib/bundler/cli/install.rb#L60(当真@bundler_version >= Gem::Version.new("1.14")
  2. https://github.com/bundler/bundler/blob/67320924db1f1910b17fae0a9268b02077874d26/lib/bundler/cli/install.rb#L62

这并不意味着您的 gem 被加载了两次(如前所述,它正在处理 Ruby 的require实现)。但是,当您尝试从 gemfile 打印一些信息时,这很烦人。

如果您的问题与一次打印一些信息有关,那么解决方法可能是(没有更好的):

if $YOUR_ONCE_CHECK.nil?
  puts "Doing it only once"
  $YOUR_ONCE_CHECK = true
end

我将在下面放置相应的堆栈跟踪以获取详细信息:

gems/bundler-1.17.0/lib/bundler/dsl.rb:47:in `instance_eval'
gems/bundler-1.17.0/lib/bundler/dsl.rb:47:in `eval_gemfile'
gems/bundler-1.17.0/lib/bundler/plugin.rb:60:in `gemfile_install'
gems/bundler-1.17.0/lib/bundler/cli/install.rb:60:in `run'
gems/bundler-1.17.0/lib/bundler/cli.rb:235:in `block in install'
gems/bundler-1.17.0/lib/bundler/settings.rb:143:in `temporary'
gems/bundler-1.17.0/lib/bundler/cli.rb:234:in `install'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
gems/bundler-1.17.0/lib/bundler/cli.rb:27:in `dispatch'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
gems/bundler-1.17.0/lib/bundler/cli.rb:18:in `start'
gems/bundler-1.17.0/exe/bundle:30:in `block in <top (required)>'
gems/bundler-1.17.0/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
gems/bundler-1.17.0/exe/bundle:22:in `<top (required)>'
bin/bundle:23:in `load'
bin/bundle:23:in `<main>'

另一个电话:

gems/bundler-1.17.0/lib/bundler/dsl.rb:47:in `instance_eval'
gems/bundler-1.17.0/lib/bundler/dsl.rb:47:in `eval_gemfile'
gems/bundler-1.17.0/lib/bundler/dsl.rb:12:in `evaluate'
gems/bundler-1.17.0/lib/bundler/definition.rb:34:in `build'
gems/bundler-1.17.0/lib/bundler.rb:135:in `definition'
gems/bundler-1.17.0/lib/bundler/cli/install.rb:62:in `run'
gems/bundler-1.17.0/lib/bundler/cli.rb:235:in `block in install'
gems/bundler-1.17.0/lib/bundler/settings.rb:143:in `temporary'
gems/bundler-1.17.0/lib/bundler/cli.rb:234:in `install'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor.rb:387:in `dispatch'
gems/bundler-1.17.0/lib/bundler/cli.rb:27:in `dispatch'
gems/bundler-1.17.0/lib/bundler/vendor/thor/lib/thor/base.rb:466:in `start'
gems/bundler-1.17.0/lib/bundler/cli.rb:18:in `start'
gems/bundler-1.17.0/exe/bundle:30:in `block in <top (required)>'
gems/bundler-1.17.0/lib/bundler/friendly_errors.rb:124:in `with_friendly_errors'
gems/bundler-1.17.0/exe/bundle:22:in `<top (required)>'
bin/bundle:23:in `load'
bin/bundle:23:in `<main>'
于 2018-11-19T10:17:17.763 回答