[Rails]Herokuにデプロイするときにrake assets:precompileで失敗する

自分用メモ。

Ruby on rails 5 でローカル環境では完全に動くのにGithub経由でHerokuにデプロイするときにrake assets:precompileで失敗した。

↓Herokuデプロイ時の失敗ログ

```
Running: rake assets:precompile
       Yarn executable was not detected in the system.
       Download Yarn at https://yarnpkg.com/en/docs/install
       rake aborted!
       ExecJS::RuntimeError: invalid token
       (execjs):3976
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/duktape_runtime.rb:9:in `exec_string'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/duktape_runtime.rb:9:in `initialize'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/runtime.rb:57:in `new'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/runtime.rb:57:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/module.rb:27:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:184:in `context'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
       
       Caused by:
       Duktape::SyntaxError: invalid token (line 3976)
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/duktape_runtime.rb:9:in `exec_string'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/duktape_runtime.rb:9:in `initialize'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/runtime.rb:57:in `new'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/runtime.rb:57:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/module.rb:27:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:184:in `context'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:221:in `run_uglifyjs'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/uglifier-4.2.0/lib/uglifier.rb:166:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/compressing.rb:65:in `block in js_compressor='
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy_proc_processor.rb:31:in `call'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:60:in `block in load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/loader.rb:44:in `load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/cached_environment.rb:47:in `load'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:66:in `find_asset'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:142:in `block in find'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:209:in `stat_directory'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/path_utils.rb:227:in `stat_tree'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `each'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/legacy.rb:104:in `logical_paths'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:140:in `find'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/sprockets/manifest.rb:186:in `compile'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-3.7.2/lib/rake/sprocketstask.rb:147:in `with_logger'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/sprockets-rails-3.2.1/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
       /tmp/build_e23ab149d6fa126c6be2f39a86b4a50b/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
       Tasks: TOP => assets:precompile
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !
 !     Push rejected, failed to compile Ruby app.
 !     Push failed
```

これはどこでエラーになっているのかわからん。
調べてみると↓のように「JSファイルのどっかにコンマとかセミコロンのタイプミスがあるんじゃないか」という意見もあったけど、

>Your are missing 'comma' sign or 'semicolon' sign somewhere in your application.js file.

[Error when running rake assets:precompile](https://stackoverflow.com/questions/8904602/error-when-running-rake-assetsprecompile/20251399)

確かに直前にJSファイルをいじったが思い当たるファイルをくまなく探してもそれっぽいタイプミスは見当たらなかった。

#解決した

結局、Heroku上でプリコンパイルされたファイルが残っていて、それについてはコンパイル済みなのでエラーログに出てこず、どこにエラーがあるか探しきれない。
ということでHerokuコンソールからプリコンパイル済みファイルを削除

```
$ rake assets:clobber RAILS_ENV=production
```

次に、再生成

```
$ rake assets:precompile RAILS_ENV=production
```

これでGithub経由のデプロイがふつうに通った。
まさかこれアセットファイルをいじったときに毎回せなあかんのか・・・？