ArgumentError:无效选项:将Rails 5应用程序部署到Heroku时和谐

时间:2019-01-16 19:21:48

标签: ruby-on-rails heroku ruby-on-rails-5

我是Heroku的新手,由于与Uglifier相关的错误,我无法部署我的Rails 5应用程序的更新版本。

我目前在Heroku上部署了我的应用程序的一个版本,但是我的JS文件都没有加载在那里。它们可以在localhost:3000上加载并正常运行。

我认为这是与Uglifier有关的问题。在阅读了关于SO的另一个人的类似问题之后,我尝试了降级Uglifier gem的解决方案。我的Gemfile先前指定了“> = 1.3.0”,因此Heroku自动安装了4.1.20。因此,我将Gemfile更改为:gem'uglifier','〜> 3.0.4')。

不过,当我现在按下Heroku时,会收到以下错误消息:

...
remote:        Installing uglifier 3.0.4
remote:        Bundle complete! 24 Gemfile dependencies, 77 gems now installed.
remote:        Gems in the groups development and test were not installed.
remote:        Bundled gems are installed into ./vendor/bundle.
remote:        Bundle completed (3.33s)
remote:        Cleaning up the bundler cache.
remote:        Warning: the running version of Bundler (1.15.2) is older than the version that created the lockfile (1.16.2). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
remote:        Removing uglifier (4.1.20)
remote:        The latest bundler is 2.0.1, but you are currently running 1.15.2.
remote:        To update, run `gem install bundler`
remote: -----> Installing node-v10.14.1-linux-x64
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        ArgumentError: Invalid option: harmony
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/uglifier-3.0.4/lib/uglifier.rb:129:in `block in initialize'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/uglifier-3.0.4/lib/uglifier.rb:128:in `each'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/uglifier-3.0.4/lib/uglifier.rb:128:in `initialize'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/config/environments/production.rb:26:in `new'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/config/environments/production.rb:26:in `block in <main>
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/railtie.rb:216:in `instance_eval'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/railtie.rb:216:in `configure'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/config/environments/production.rb:1:in `<main>'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:602:in `block (2 levels) in <class:Engine>'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:601:in `each'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/engine.rb:601:in `block in <class:Engine>'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `instance_exec'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:32:in `run'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:61:in `block in run_initializers'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `each'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:50:in `tsort_each_child'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/initializable.rb:60:in `run_initializers'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:361:in `initialize!'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/config/environment.rb:5:in `<main>'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `block in require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:257:in `load_dependency'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/dependencies.rb:291:in `require'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:337:in `require_environment!'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/railties-5.2.2/lib/rails/application.rb:520:in `block in run_tasks_blocks'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:62:in `block (2 levels) in define'
remote:        /tmp/build_5ce011f911fe1c351bbce1885a611ecb/vendor/bundle/ruby/2.5.0/gems/rake-12.3.2/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => environment
remote:        (See full trace by running task with --trace)
remote: 
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed

production.rb文件的第26行是这样的:
config.assets.js_compressor = Uglifier.new(harmony:true)

关于我在做什么错的任何想法?和谐与该版本的Uglifier不兼容吗?

1 个答案:

答案 0 :(得分:1)

终于成功了!我必须进入我的application.js文件并删除'/ = require jquery-ujs'。该文件已经包含“ / = require rails-ujs”,因此不需要jquery-ujs(就我而言,这完全阻止了我的应用正常运行!)。

我的application.js文件:

    //= require jquery
    //= require rails-ujs
    //= require activestorage
    //= require_tree .

说实话,我在控制台中收到一条警告,提示您不需要同时使用这两项。但是,由于我在本地未遇到任何与JS / jQuery相关的问题,因此我忽略了该警告。瞧,这是阻止我的JS文件正确加载到Heroku上的罪魁祸首。故事的寓意:不要忽略那些警告。