Heroku push - ExecJS::RuntimeError: SyntaxError: Name expected

Heroku push - ExecJS::RuntimeError: SyntaxError: Name expected

推送到 Heroku 时遇到以下错误。前几天工作正常。我尝试推送的提交没有重大配置更改。我对如何解决这个问题感到困惑。 Rails 5.1 应用程序使用以下构建包:

1. heroku/nodejs
2. heroku/ruby

我正在使用 webpacker 和 yarn。我认为这与它有关,但无法挖掘更多信息。

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        yarn install v0.27.5
remote:        [1/4] Resolving packages...
remote:        [2/4] Fetching packages...
remote:        warning fsevents@1.1.2: The platform "linux" is incompatible with this module.
remote:        info "fsevents@1.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
remote:        [3/4] Linking dependencies...
remote:        [4/4] Building fresh packages...
remote:        Done in 6.62s.
remote:        rake aborted!
remote:        ExecJS::RuntimeError: SyntaxError: Name expected
remote:        JS_Parse_Error.get ((execjs):3538:621)
remote:        (execjs):4060:47
remote:        (execjs):1:102
remote:        Object.<anonymous> ((execjs):1:120)
remote:        Module._compile (module.js:571:32)
remote:        Object.Module._extensions..js (module.js:580:10)
remote:        Module.load (module.js:488:32)
remote:        tryModuleLoad (module.js:447:12)
remote:        Function.Module._load (module.js:439:3)
remote:        Module.runMain (module.js:605:10)
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:53:in `call'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/uglifier_compressor.rb:28:in `call'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `call_processors'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:134:in `load_from_unloaded'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:60:in `block in load'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/loader.rb:44:in `load'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:66:in `find_asset'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/base.rb:73:in `find_all_linked_assets'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:142:in `block in find'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:228:in `block in stat_tree'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:212:in `block in stat_directory'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `each'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:209:in `stat_directory'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/path_utils.rb:227:in `stat_tree'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `each'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:105:in `block in logical_paths'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `each'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/legacy.rb:104:in `logical_paths'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:140:in `find'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/sprockets/manifest.rb:185:in `compile'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:68:in `block (3 levels) in define'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-3.7.1/lib/rake/sprocketstask.rb:147:in `with_logger'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/sprockets-rails-3.2.0/lib/sprockets/rails/task.rb:67:in `block (2 levels) in define'
remote:        /tmp/build_d7b1075d17c0c421422ebdbfc017919a/vendor/bundle/ruby/2.4.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'
remote:        Tasks: TOP => assets:precompile
remote:        (See full trace by running task with --trace)
remote:  !
remote:  !     Precompiling assets failed.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !   Push rejected ....

进一步研究,发现问题与Uglifier有关。当我将第三方库 datepicker.js 的内容复制并粘贴到 Uglifier 中时,我得到了同样的错误:

> Uglifier.compile( <<< file contents >>> )
ExecJS::RuntimeError: SyntaxError: Name expected
from JS_Parse_Error.get ((execjs):3538:621)

我认为问题与您 linux 服务器上的 yarn 安装有关

事实上,您可以在 yarn github 存储库中找到该文件

Yarn fsevents-1.1.2

您还可以找到类似的问题,其中 yarn 的 heroku 安装会失败并出现相同的错误 warning fsevents@1.1.2: The platform "linux" is incompatible with this module.

错误一样 警告 fsevents@1.1.2:平台“linux”与该模块不兼容。信息“fsevents@1.1.2”是一个可选的依赖项,兼容性检查失败。从安装中排除它。

Heroku fails to install yarn on linux platform

Yarn 是在 Rails 5.1 中添加的,我也不得不解决这个错误,我也在 SO 上打开了一个问题。

我的问题出在开发中,因为我有 Linux Mint。可能在开发中安装 yarn 让我在生产中没有遇到问题。

我在开发中使用 node.js 安装它时仍然遇到问题所以我最终使用 npm 命令 npm install yarn -g 你可以 运行 在你的 heroku 服务器上使用 heroku run npm install yarn -g 或者你可以使用 nodejs,yarn 安装指南是听到

https://yarnpkg.com/en/docs/install

这也是对非常相似的问题列表的查询,您可以阅读那些 post 并可能找到问题的解决方案。这个问题不是来自 ruby on rails,而是其他使用 nodejs.

的框架

在这种情况下,您还安装了带有 nodejs 的 yarn,所以问题可能与 nodejs 有关

https://duckduckgo.com/?q=heroku+yarn+installation+The+platform+%22linux%22+is+incompatible&atb=v52-6_b&ia=qa

FSEvents的解释API

This appears to be a dependency problem with fsevents. Your OS, Arch Linux, doesn't support it. If you head over to Strongloop's fsevents Github page, you'll see this in their README

Native access to OS X FSEvents in Node.js The FSEvents API in OS X allows applications to register for notifications of changes to a given directory tree. It is a very fast and lightweight alternative to kqueue. So, I would say this isn't a Yarn issue. The other errors are probably a result of the previous failing.

阅读更多内容

https://github.com/yarnpkg/yarn/issues/2142

无论如何他们应该用这个修复程序解决这个问题

https://github.com/yarnpkg/yarn/pull/2279

如果你不能解决这个问题,也许你可以提出一个问题

我发现此问题的原因与 Uglifier 尝试处理名为 js-datepicker (datepicker.js) 的第三方库时可能存在的错误有关。我在 Uglifier Github 上打开了一个问题:https://github.com/lautis/uglifier/issues/124

我通过在我的 app/assets/javascripts/application.js 文件中包含缩小的 js-datepicker 来解决这个问题。

//= require js-datepicker/datepicker.min