RAILS_ENV=生产轨道资产:预编译不适用于 RSpec
Posted
技术标签:
【中文标题】RAILS_ENV=生产轨道资产:预编译不适用于 RSpec【英文标题】:RAILS_ENV=production rails assets:precompile not working with RSpec 【发布时间】:2019-10-01 20:57:26 【问题描述】:我正在尝试运行
RAILS_ENV=production rails assets:precompile
我收到一个错误 NameError: uninitialized constant RSpec。我该如何摆脱这个错误?
一些上下文:我正在尝试在将图像和 css 文件发送到 AWS Beanstalk 之前对其进行预编译。很像这个问题 RoR App:“资产管道中不存在资产'application.css'”在移动到生产服务器后RoR App: "The asset 'application.css' is not present in the asset pipeline" after moving to production server
堆栈跟踪:
[15:49:45] [master] /xxx/CaIng : RAILS_ENV=production rails assets:precompile --trace
rails aborted!
NameError: uninitialized constant RSpec
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:79:in `block in load_missing_constant'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:8:in `without_bootsnap_cache'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:79:in `rescue in load_missing_constant'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:58:in `load_missing_constant'
/xxx/CaIng/lib/tasks/custom_rspec.rake:3:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `block in run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `each'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/application.rb:515:in `run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:459:in `load_tasks'
/xxx/CaIng/Rakefile:6:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:103:in `load_rakefile'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:22:in `block in perform'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:9:in `<main>'
Caused by:
NameError: uninitialized constant RSpec
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:60:in `block in load_missing_constant'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:16:in `allow_bootsnap_retry'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/active_support.rb:59:in `load_missing_constant'
/xxx/CaIng/lib/tasks/custom_rspec.rake:3:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `block in run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `each'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:650:in `run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/application.rb:515:in `run_tasks_blocks'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/engine.rb:459:in `load_tasks'
/xxx/CaIng/Rakefile:6:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/rake_module.rb:29:in `load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:703:in `raw_load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:104:in `block in load_rakefile'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:103:in `load_rakefile'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:22:in `block in perform'
/Users/flo/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/rake-12.3.2/lib/rake/application.rb:186:in `standard_exception_handling'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands/rake/rake_command.rb:20:in `perform'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/command.rb:48:in `invoke'
/xxx/CaIng/.gems/gems/railties-5.2.3/lib/rails/commands.rb:18:in `<main>'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
/xxx/CaIng/.gems/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
bin/rails:9:in `<main>'
我的宝石文件:
source 'https://rubygems.org'
git_source(:github) |repo| "https://github.com/#repo.git"
ruby '2.6.3'
gem 'rails', '~> 5.2.3'
gem 'pg', '>= 0.18', '< 2.0'
gem 'puma', '~> 3.11'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'aws-sdk'
gem 'coffee-rails', '~> 4.2'
gem 'turbolinks', '~> 5'
gem 'jbuilder', '~> 2.5'
gem 'bootsnap', '>= 1.1.0', require: false
group :development, :test do
debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'capybara'
gem 'rspec-rails'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'rails-controller-testing'
gem 'selenium-webdriver'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
end
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
gem 'devise'
【问题讨论】:
你能发布完整的堆栈跟踪吗? 【参考方案1】:你不应该在开发组中拥有这些 gem,只有 byebug 应该在两个组中。
group :development, :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :test do
gem 'capybara'
gem 'rspec-rails'
gem 'database_cleaner'
gem 'factory_bot_rails'
gem 'rails-controller-testing'
gem 'selenium-webdriver'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
end
【讨论】:
感谢您的回复。我移动了宝石以匹配您上面的内容。然后我保存了。我跑了捆绑安装。然后我再次运行 RAILS_ENV=production rails assets:precompile ,我得到了同样的错误。以上是关于RAILS_ENV=生产轨道资产:预编译不适用于 RSpec的主要内容,如果未能解决你的问题,请参考以下文章