rails / execjs

Run JavaScript code from Ruby
MIT License
538 stars 282 forks source link

ExecJS::RuntimeError: SyntaxError: [stdin]:10:10: unexpected newline #96

Closed viktorianer closed 3 years ago

viktorianer commented 3 years ago

I see this error on Heroku with new heroku-20 stack during a new deployment and local (without docker), if I run:

rails assets:precompile RAILS_ENV=production --trace

I found this issue after updating to heroku-20 stack today, after seeing Heroku warning:

This app is using the Heroku-16 stack, which is deprecated:
remote: https://devcenter.heroku.com/changelog-items/1958
...
Please upgrade to a newer stack as soon as possible:
remote: https://devcenter.heroku.com/articles/upgrading-to-the-latest-stack

With heroku-18 stack and my docker config (https://github.com/viktorianer/rails-community-app), I do not have any problems to precompile my assets. 🥇 It is in master, because I had no problems during development and upgrading with docker stack.

execjs dependencies in my project:

rails (6.0.3.4)
...
autoprefixer-rails (10.2.0.0)
      execjs
...
coffee-script (2.4.1)
      coffee-script-source
      execjs
...
execjs (2.7.0)
...
RUBY VERSION
   ruby 2.6.6p146

BUNDLED WITH
   2.1.4

Stack trace:

remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        rake aborted!
remote:        ExecJS::RuntimeError: SyntaxError: [stdin]:10:10: unexpected newline
remote:        compile ((execjs):7528:19)
remote:        eval (eval at <anonymous> ((execjs):7539:8), <anonymous>:1:10)
remote:        (execjs):7539:8
remote:        (execjs):7545:14
remote:        (execjs):1:40
remote:        Object.<anonymous> ((execjs):1:58)
remote:        Module._compile (internal/modules/cjs/loader.js:1063:30)
remote:        Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
remote:        Module.load (internal/modules/cjs/loader.js:928:32)
remote:        Function.Module._load (internal/modules/cjs/loader.js:769:14)
remote:        Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
remote:        internal/main/run_main_module.js:17:47
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:39:in `exec'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:21:in `eval'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/execjs-2.7.0/lib/execjs/external_runtime.rb:46:in `call'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/coffee-script-2.4.1/lib/coffee_script.rb:78:in `compile'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/coffee_script_processor.rb:24:in `block in call'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/cache.rb:92:in `fetch'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/coffee_script_processor.rb:23:in `call'
remote:        /tmp/build_0a31eb37/vendor/bundle/ruby/2.6.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84:in `call_processor'
...
viktorianer commented 3 years ago

I found a fix for me. In my app I use ENV in one asset, and I did not set these envs before deployment. So, my fail.

But, it would be nice to have some error messages with help.

Sight note: For the first time I had to define engines.node and engines.yarn in packages.json, because Heroku-20 stack use a node (default ~14) and yarn (default ~.1.21) version, which is not working with my app setup. After adding this, Heroku use versions specified by my packages.json and is not using default version for this Heroku-20 stack.