Javascript无法在Heroku上运行,但可以在本地运行,我该如何解决呢?

时间:2019-04-27 16:44:26

标签: javascript ruby-on-rails heroku

我能够推送我的代码并将其部署到Heroku,而之前该代码已在Cloud9上本地运行。我将红宝石的构建包挂在了轨道上,并添加了一个postgres数据库,以避免部署错误。当我查看已部署的代码时,页面的javascript被禁用。

我已经尝试摆脱了我的application.rb文件中所需的// =树,删除了gemlock文件,安装了一个sass替代方案,因为当前的替代方案已贬值,heroku资产已清理并重新启动。并运行rake资产:针对本地和heroku进行预编译

这是在heroku run rake assets:precompile

之后
NoMethodError: undefined method `[]' for nil:NilClass
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:278:in `sprockets_context'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:124:in `asset_path'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:137:in `asset_url'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_processor.rb:209:in `font_url'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/funcall.rb:151:in `block in _perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:108:in `block in with_function'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:135:in `with_frame'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:108:in `with_function'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/funcall.rb:149:in `_perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/node.rb:50:in `perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/list_literal.rb:75:in `block in _perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/list_literal.rb:75:in `map'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/list_literal.rb:75:in `_perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/script/tree/node.rb:50:in `perform'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:398:in `visit_prop'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:36:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:158:in `block in visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:79:in `block in with_base'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:135:in `with_frame'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:79:in `with_base'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:158:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:513:in `block (2 levels) in visit_directive'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:513:in `map'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:513:in `block in visit_directive'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:179:in `with_environment'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:512:in `visit_directive'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:36:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:158:in `block in visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:79:in `block in with_base'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:135:in `with_frame'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/stack.rb:79:in `with_base'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:158:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:52:in `map'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:167:in `block in visit_children'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:179:in `with_environment'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:166:in `visit_children'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:186:in `visit_root'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/base.rb:36:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:157:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/visitors/perform.rb:10:in `visit'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/root_node.rb:36:in `css_tree'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/tree/root_node.rb:20:in `render'
/app/vendor/bundle/ruby/2.5.0/gems/sass-3.7.4/lib/sass/engine.rb:290:in `render'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_compressor.rb:48:in `call'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/sass_compressor.rb:28:in `call'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:134:in `block in find'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `each'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:133:in `find'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
/app/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
/app/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli.rb:360:in `exec'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/cli.rb:10:in `start'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.5.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => assets:precompile

我一直在寻找一个功能齐全的网站,但是将其推送到heroku似乎导致该应用程序本应具有任何javascript功能。请帮忙,对那些烦人的帖子表示抱歉,但我真的很想知道这件事。

2 个答案:

答案 0 :(得分:0)

如果使用的是rails-bootstrap gem,则有一个名为bootstrap.coffee.js的文件。您可以尝试将其删除,看看是否可行。

此外,您还可以尝试以这种方式推送它(在将其推送到heroku之前进行预编译):

rake assets:precompile RAILS_ENV=production
git add .
git commit -a -m "JS"
git push heroku master

如果其他方法都不起作用,请通过config / environments / production.rb:

config.assets.compile = true 

不建议采用最后一种方法。

答案 1 :(得分:0)

我发现我的assets.rbapplication.js文件中缺少正确的文件。之后,我如上所述进行了预编译和推送,然后成功了!谢谢你们的帮助!