horihorikeita
@horihorikeita (kon desu)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

rails をHerokuでデプロイしたい

解決したいこと

Ruby on RailsでWebアプリをつくっています。
herokuにデプロイしようと git push heroku master をするとエラーが発生しました。
解決方法を教えて下さい。

発生している問題・エラー

ターミナル

 %git push heroku master
Enumerating objects: 6845, done.
省略
Uglifier::Error: Unexpected token: keyword (const). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).
省略
remote:         2302 
remote:           => const nav document.getElementsByClassName("nav-js")[0];


省略

remote:  !     Precompiling assets failed.
省略
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/cryptic-everglades-97405.git'

=> const nav document.getElementsByClassName("nav-js")[0];
が赤くなっている

該当するソースコード

aplication.js
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require rails-ujs
//= require activestorage
//= require_tree .

const nav = document.getElementsByClassName("nav-js")[0];
const button = document.getElementsByClassName("js-nav-button")[0];

button.addEventListener("click", () => {
  nav.classList.toggle("active");

  if (nav.classList.contains("active")) {
    button.classList.add("active");
  } else {
    button.classList.remove("active");
  }
});
config/environments/production.rb
 config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?

  # Compress JavaScripts and CSS.
  config.assets.js_compressor = Uglifier.new(harmony: true)
  # config.assets.css_compressor = :sass

  # Do not fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = true


自分で試したこと

config/environments/production.rb
に config.assets.js_compressor = Uglifier.new(harmony: true)
を記述したがエラーが発生する

0

1Answer

正しい方法ではないかもしれませんが、一次対応としてconstではなくvarを使うとどうでしょうか?

0Like

Your answer might help someone💌