无法使用资产重复NilClass on rails rake:precompile

时间:2021-02-05 20:40:59

When I try to precompile my assets I get the following error. This is the trace with the full output:

当我尝试预编译我的资产时,我收到以下错误。这是具有完整输出的跟踪:

RAILS_ENV=production bundle exec rake assets:precompile --trace
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
rake aborted!
TypeError: can't dup NilClass
/var/lib/gems/2.3.0/gems/redis-activesupport-5.0.3/lib/active_support/cache/redis_store.rb:38:in `dup'
/var/lib/gems/2.3.0/gems/redis-activesupport-5.0.3/lib/active_support/cache/redis_store.rb:38:in `map'
/var/lib/gems/2.3.0/gems/redis-activesupport-5.0.3/lib/active_support/cache/redis_store.rb:38:in `initialize'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/cache.rb:60:in `new'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/cache.rb:60:in `lookup_store'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/application/bootstrap.rb:64:in `block in <module:Bootstrap>'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/initializable.rb:30:in `instance_exec'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/initializable.rb:30:in `run'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/initializable.rb:55:in `block in run_initializers'
/usr/lib/ruby/2.3.0/tsort.rb:228:in `block in tsort_each'
/usr/lib/ruby/2.3.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
/usr/lib/ruby/2.3.0/tsort.rb:431:in `each_strongly_connected_component_from'
/usr/lib/ruby/2.3.0/tsort.rb:349:in `block in each_strongly_connected_component'
/usr/lib/ruby/2.3.0/tsort.rb:347:in `each'
/usr/lib/ruby/2.3.0/tsort.rb:347:in `call'
/usr/lib/ruby/2.3.0/tsort.rb:347:in `each_strongly_connected_component'
/usr/lib/ruby/2.3.0/tsort.rb:226:in `tsort_each'
/usr/lib/ruby/2.3.0/tsort.rb:205:in `tsort_each'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/initializable.rb:54:in `run_initializers'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/application.rb:352:in `initialize!'
/home/alex/Dev/livingrecipe/config/environment.rb:5:in `<top (required)>'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:293:in `require'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:293:in `block in require'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:259:in `load_dependency'
/var/lib/gems/2.3.0/gems/activesupport-5.0.5/lib/active_support/dependencies.rb:293:in `require'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/application.rb:328:in `require_environment!'
/var/lib/gems/2.3.0/gems/railties-5.0.5/lib/rails/application.rb:448:in `block in run_tasks_blocks'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/var/lib/gems/2.3.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `block in execute'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `each'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:250:in `execute'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:194:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:216:in `block in invoke_prerequisites'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:214:in `each'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:214:in `invoke_prerequisites'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:193:in `block in invoke_with_call_chain'
/usr/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:187:in `invoke_with_call_chain'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/task.rb:180:in `invoke'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:152:in `invoke_task'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block (2 levels) in top_level'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `each'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:108:in `block in top_level'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:117:in `run_with_threads'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:102:in `top_level'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:80:in `block in run'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:178:in `standard_exception_handling'
/var/lib/gems/2.3.0/gems/rake-12.0.0/lib/rake/application.rb:77:in `run'
/var/lib/gems/2.3.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'

So unfortunately I can't figure out where the error is pointing to as none of the code is my stuff and mainly the trace consists of code from the default gems. The one thing that I can see that I have added in there is the bootstrap gem, but the same thing happens even if I take that out.

所以不幸的是我无法弄清楚错误指向的位置,因为没有代码是我的东西,主要是跟踪由默认宝石的代码组成。我可以看到我添加的一件事是引导宝石,但即使我把它拿出来也会发生同样的事情。

4 个解决方案

#1


0  

It looks like you have incorrect redis connection (or setup)

看起来你有不正确的redis连接(或设置)

To debug it:

要调试它:

1) Debug redis connection with in rails console. Using Redis from your application

1)使用rails控制台调试redis连接。从您的应用程序中使用Redis

>> require 'rubygems'
=> false
>> require 'redis'
=> true
>> r = Redis.new
=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>
>> r.ping
=> "PONG"
>> r.set('foo','bar')
=> "OK"
>> r.get('foo')
=> "bar"

2) Debug RedisStore

2)调试RedisStore

RedisStore.new("localhost:6379/0/cache", expires_in: 90.minutes)

3) If the command passed, set up this config for your app like it's described in gem redis-rails

3)如果命令通过,请为您的应用程序设置此配置,就像在gem redis-rails中描述的那样

# config/application.rb
config.cache_store = :redis_store, "redis://localhost:6379/0/cache", { expires_in: 90.minutes }

4) Play with configuration a little to establish successful connection to redis (And don't forget about different environment configs in production!!!)

4)使用配置稍微建立与redis的成功连接(并且不要忘记生产中的不同环境配置!)

5) Commit changes, redeploy.

5)提交更改,重新部署。

#2


0  

You're trying to compile assets in the production environment, but you're also on your dev machine. Are you sure you've configured a production environment in all of your config files? Look in config/cable.yml and config/redis.yml if they exist.

您正在尝试在生产环境中编译资产,但您也在开发计算机上。您确定已在所有配置文件中配置了生产环境吗?查看config / cable.yml和config / redis.yml(如果存在)。

Alternatively, a good way to compile assets in the development environment is:

或者,在开发环境中编译资产的好方法是:

RAILS_ENV=development bundle exec rake assets:precompile

However, after doing this, Rails will use these compiled assets in development instead of your assets in app/assets. Eventually, you'll also want to run RAILS_ENV=development bundle exec rake assets:clobber or rm -rf public/assets to clear your development environment of these compiled assets.

但是,执行此操作后,Rails将在开发中使用这些编译的资产,而不是app / assets中的资产。最后,您还需要运行RAILS_ENV =开发包exec rake资产:clobber或rm -rf public / assets以清除这些编译资产的开发环境。

#3


0  

from the stack trace you submitted, it looks like you should check the value of

从你提交的堆栈跟踪中,看起来你应该检查它的值

config.cache_store

it most probably empty:

它很可能是空的:

https://github.com/rails/rails/blob/87eb1a26da0b1385af07a8347dcfd32998a614ee/railties/lib/rails/application/bootstrap.rb#L67

#4


0  

So not sure what the problem was, but i updated ruby, rails and all my gems and that got rid of the problem. So thinking it was a compatibility issue with version mismatch somewhere

所以不确定问题是什么,但我更新了ruby,rails和我所有的宝石,并解决了这个问题。所以认为这是版本不匹配的兼容性问题

#1


0  

It looks like you have incorrect redis connection (or setup)

看起来你有不正确的redis连接(或设置)

To debug it:

要调试它:

1) Debug redis connection with in rails console. Using Redis from your application

1)使用rails控制台调试redis连接。从您的应用程序中使用Redis

>> require 'rubygems'
=> false
>> require 'redis'
=> true
>> r = Redis.new
=> #<Redis client v2.2.1 connected to redis://127.0.0.1:6379/0 (Redis v2.3.8)>
>> r.ping
=> "PONG"
>> r.set('foo','bar')
=> "OK"
>> r.get('foo')
=> "bar"

2) Debug RedisStore

2)调试RedisStore

RedisStore.new("localhost:6379/0/cache", expires_in: 90.minutes)

3) If the command passed, set up this config for your app like it's described in gem redis-rails

3)如果命令通过,请为您的应用程序设置此配置,就像在gem redis-rails中描述的那样

# config/application.rb
config.cache_store = :redis_store, "redis://localhost:6379/0/cache", { expires_in: 90.minutes }

4) Play with configuration a little to establish successful connection to redis (And don't forget about different environment configs in production!!!)

4)使用配置稍微建立与redis的成功连接(并且不要忘记生产中的不同环境配置!)

5) Commit changes, redeploy.

5)提交更改,重新部署。

#2


0  

You're trying to compile assets in the production environment, but you're also on your dev machine. Are you sure you've configured a production environment in all of your config files? Look in config/cable.yml and config/redis.yml if they exist.

您正在尝试在生产环境中编译资产,但您也在开发计算机上。您确定已在所有配置文件中配置了生产环境吗?查看config / cable.yml和config / redis.yml(如果存在)。

Alternatively, a good way to compile assets in the development environment is:

或者,在开发环境中编译资产的好方法是:

RAILS_ENV=development bundle exec rake assets:precompile

However, after doing this, Rails will use these compiled assets in development instead of your assets in app/assets. Eventually, you'll also want to run RAILS_ENV=development bundle exec rake assets:clobber or rm -rf public/assets to clear your development environment of these compiled assets.

但是,执行此操作后,Rails将在开发中使用这些编译的资产,而不是app / assets中的资产。最后,您还需要运行RAILS_ENV =开发包exec rake资产:clobber或rm -rf public / assets以清除这些编译资产的开发环境。

#3


0  

from the stack trace you submitted, it looks like you should check the value of

从你提交的堆栈跟踪中,看起来你应该检查它的值

config.cache_store

it most probably empty:

它很可能是空的:

https://github.com/rails/rails/blob/87eb1a26da0b1385af07a8347dcfd32998a614ee/railties/lib/rails/application/bootstrap.rb#L67

#4


0  

So not sure what the problem was, but i updated ruby, rails and all my gems and that got rid of the problem. So thinking it was a compatibility issue with version mismatch somewhere

所以不确定问题是什么,但我更新了ruby,rails和我所有的宝石,并解决了这个问题。所以认为这是版本不匹配的兼容性问题