预编译 rails 资产导致未定义的方法目录? nil:NilClass

Precompiling rails assets caused undefined method directory? for nil:NilClass

我正在尝试在我的 rails 应用程序中预编译资产,并得到这个

$ ber assets:precompile --trace
DL is deprecated, please use Fiddle
DL is deprecated, please use Fiddle
** Invoke assets:precompile (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke environment (first_time)
** Execute environment
** Execute assets:precompile
rake aborted!
NoMethodError: undefined method `directory?' for nil:NilClass
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:307:in `block in each_entry'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:303:in `each'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:303:in `each_entry'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:322:in `block in each_file'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:321:in `each'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:321:in `each_file'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/base.rb:335:in `each_logical_path'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/manifest.rb:115:in `each'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/manifest.rb:115:in `to_a'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/sprock
ets/manifest.rb:115:in `compile'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-rails-2.2.4/lib/s
prockets/rails/task.rb:70:in `block (3 levels) in define'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-2.12.3/lib/rake/s
procketstask.rb:146:in `with_logger'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-rails-2.2.4/lib/s
prockets/rails/task.rb:69:in `block (2 levels) in define'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:240:in `call'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:240:in `block in execute'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:235:in `each'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:235:in `execute'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:179:in `block in invoke_with_call_chain'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/monitor.rb:211:in `mon_synchronize'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:172:in `invoke_with_call_chain'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/task.r
b:165:in `invoke'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:150:in `invoke_task'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:106:in `block (2 levels) in top_level'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:106:in `each'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:106:in `block in top_level'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:115:in `run_with_threads'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:100:in `top_level'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:78:in `block in run'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:176:in `standard_exception_handling'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/lib/rake/applic
ation.rb:75:in `run'
c:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rake-10.4.2/bin/rake:33:in
`<top (required)>'
c:/RailsInstaller/Ruby2.1.0/bin/rake:23:in `load'
c:/RailsInstaller/Ruby2.1.0/bin/rake:23:in `<main>'
Tasks: TOP => assets:precompile

当我在 application.js.erb 中引用一个不再存在的目录时,我遇到了同样的错误。它也可能是一个损坏的软链接,可能会导致此错误,但我看到你在 Windows 上,所以几乎可以 100% 排除。

在您引用其他文件或存在但已删除的目录的情况下,检查您的资产文件是否存在输入错误。