我在我的应用上做了一些工作,最近我跑了
St > Street
St. > Saint
最终结果是这个错误:
rake assets:precompile:primary RAILS_ENV=production --trace
根本没有提供信息,跟踪对我没什么帮助
NoMethodError: undefined method 'bytesize' for nil:NilClass
这是我的生产环境文件。
** Invoke assets:precompile:primary (first_time)
** Invoke assets:environment (first_time)
** Execute assets:environment
** Invoke tmp:cache:clear (first_time)
** Execute tmp:cache:clear
** Execute assets:precompile:primary
rake aborted!
NoMethodError: undefined method `bytesize' for nil:NilClass
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rack-1.4.7/lib/rack/utils.rb:300:in `bytesize'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:13:in `initialize'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:249:in `new'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:249:in `block in build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:270:in `circular_call_protection'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:248:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:60:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:105:in `each'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:249:in `new'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:249:in `block in build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:270:in `circular_call_protection'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:248:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:60:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:252:in `new'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:252:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/index.rb:60:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/environment.rb:78:in `find_asset'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-3.2.22.1/lib/sprockets/static_compiler.rb:19:in `block in compile'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:219:in `block in each_logical_path'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each_entry'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:204:in `block in each_file'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each_file'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/sprockets-2.2.3/lib/sprockets/base.rb:217:in `each_logical_path'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-3.2.22.1/lib/sprockets/static_compiler.rb:18:in `compile'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-3.2.22.1/lib/sprockets/assets.rake:56:in `internal_precompile'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/actionpack-3.2.22.1/lib/sprockets/assets.rake:70:in `block (3 levels) in <top (required)>'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:240:in `call'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:240:in `block in execute'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:235:in `each'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:235:in `execute'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/Users/jasontanner/.rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/task.rb:165:in `invoke'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:150:in `invoke_task'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:106:in `each'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:106:in `block in top_level'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:115:in `run_with_threads'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:100:in `top_level'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:78:in `block in run'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:176:in `standard_exception_handling'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/lib/rake/application.rb:75:in `run'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/gems/rake-10.5.0/bin/rake:33:in `<top (required)>'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/bin/rake:19:in `load'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/bin/rake:19:in `<main>'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
/Users/jasontanner/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile:primary
所以我的问题是这个。为什么我不能预编译我的资产以及如何解决这个问题?我正在运行Rails Galapal::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = true
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# For angular js compression
config.assets.js_compressor = Uglifier.new(mangle: false)
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
# Do not compress assets
config.assets.compress = true
config.assets..serve_static_assets = true
# Expands the lines which load the assets
config.assets.debug = false
# Expands the lines which load the assets
config.assets.debug = false
#ActiveRecord::Base.logger = Logger.new STDOUT
end
。
答案 0 :(得分:2)
我对这个问题进行了一些挖掘,似乎至少有两个原因可以解决这个问题:
1)您有空资产
2)你的一个资产中有非utf8字符(在代码中检查带有重音字符的注释等)。
通过“在application.css的底部添加一个空类”github.com/zweilove/css_splitter/issues/12来查看有关'require'的参考资料,特别是解决问题的人。也可以通过删除来尝试调试您的清单中的所有资产,然后开始逐个添加,直到它中断。祝你好运!
答案 1 :(得分:2)
我对这个问题做了一个JavaScript文件,它有一些奇怪的格式(来自更漂亮的库)Rails问题。
NoMethodError: undefined method `bytesize' for nil:NilClass
/Users/joel/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/rack-1.6.8/lib/rack/utils.rb:380:in `bytesize'
/Users/joel/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/sprockets-2.12.4/lib/sprockets/processed_asset.rb:13:in `initialize'
为了找出哪个文件,我挖掘了gem路径并添加了一些代码到sprockets/processed_asset.rb
来打印文件:
context = environment.context_class.new(environment, logical_path, pathname)
@source = context.evaluate(pathname)
p pathname
@length = Rack::Utils.bytesize(source)
下次我编辑资产时,它向我展示了罪魁祸首。