1

Upgrading chart.js from version 2.9.4 to 4.4.4. Locally(Machine is MAC OS), rails app is generating charts with upgraded version.

When deploying to AWS EC2, Jenkins build is failing with this error during assets pre-compilation step -

rails aborted!
ExecJS::RuntimeError: SyntaxError: Unexpected token: operator (=)
JS_Parse_Error.get ((execjs):3538:621)
(execjs):4077:53
(execjs):1:32
Object.<anonymous> ((execjs):1:50)
Module._compile (node:internal/modules/cjs/loader:1364:14)
Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
Module.load (node:internal/modules/cjs/loader:1203:32)
Module._load (node:internal/modules/cjs/loader:1019:12)

Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
node:internal/main/run_main_module:28:49

/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:40:in `exec'
/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:22:in `eval'
/usr/local/rvm/gems/ruby-3.1.0/gems/execjs-2.9.1/lib/execjs/external_runtime.rb:47:in `call'
/usr/local/rvm/gems/ruby-3.1.0/gems/uglifier-3.2.0/lib/uglifier.rb:195:in `run_uglifyjs'
/usr/local/rvm/gems/ruby-3.1.0/gems/uglifier-3.2.0/lib/uglifier.rb:157:in `compile'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/compressing.rb:84:in `block in js_compressor='
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:184:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:339:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:43:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:207:in `block in fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:187:in `fetch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:206:in `fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/bundle.rb:32:in `block in call'
/usr/local/rvm/gems/ruby-3.1.0/gems/set-1.1.0/lib/set.rb:501:in `each_key'
/usr/local/rvm/gems/ruby-3.1.0/gems/set-1.1.0/lib/set.rb:501:in `each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/bundle.rb:31:in `call'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:84:in `call_processor'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/processor_utils.rb:65:in `call_processors'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:184:in `load_from_unloaded'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:59:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:339:in `fetch_asset_from_dependency_cache'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/loader.rb:43:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `block in load'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:207:in `block in fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:187:in `fetch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/map.rb:206:in `fetch_or_store'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/cached_environment.rb:44:in `load'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:81:in `find_asset'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `each'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `to_a'
/usr/local/rvm/gems/ruby-3.1.0/gems/sprockets-4.2.1/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `block in synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb:48:in `synchronize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/safe_task_executor.rb:22:in `execute'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/promise.rb:564:in `block in realize'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:359:in `run_task'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:350:in `block (3 levels) in create_worker'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `loop'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:341:in `block (2 levels) in create_worker'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `catch'
/usr/local/rvm/gems/ruby-3.1.0/gems/concurrent-ruby-1.2.3/lib/concurrent-ruby/concurrent/executor/ruby_thread_pool_executor.rb:340:in `block in create_worker'
Tasks: TOP => assets:precompile

Also, when chart.js version is downgraded to 2.x then it's working.

I tried couple of solutions :

  • Set Production ENV variable EXECJS_RUNTIME="Node"
  • Upgrading Node & Yarn version similar to local machine
  • js_compressor = Uglifier so codebase already have js_compressor = Uglifier.new(harmony: true, output: { ascii_only: false })
  • Uglier gem version upgrade to 4.2
  • Also checked for RubyRacer gem but have memory issue

It seems runtime dependency for Linux environment need to be tweaked.

Please guide.

1
  • Probably you've got a JavaScript version problem, but from what you have posted here it's hard to say exactly what that is. Commented Nov 6, 2024 at 14:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.