rails / sprockets

Rack-based asset packaging system
MIT License
945 stars 788 forks source link

Obscure Coffeescript Error on Precompiling Assets #595

Open CodingAnarchy opened 5 years ago

CodingAnarchy commented 5 years ago

Expected behavior

Sprockets v4.0 should precompile my assets as expected, Sprockets v3.0 did. (I upgraded my app by adding a manifest file and following the other instructions per the upgrade guide.)

Manifest file is as follows:

//= link application.js.map
//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

Actual behavior

V8::Error: [stdin]:1:1: unexpected //= at <eval>:7528:20
at compile (<eval>:7528:19)
/Users/vision/.rvm/gems/ruby-2.5.3/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:45:in `block in call'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:75:in `block in lock'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:73:in `Locker'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:73:in `lock'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/execjs-2.7.0/lib/execjs/ruby_racer_runtime.rb:43:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/coffee-script-2.4.1/lib/coffee_script.rb:78:in `compile'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/coffee_script_processor.rb:24:in `block in call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/cache.rb:92:in `fetch'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/coffee_script_processor.rb:23:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:22:in `block in <class:CompositeProcessor>'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:33:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:145:in `load_from_unloaded'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:59:in `block in load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:329:in `fetch_asset_from_dependency_cache'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:43:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/cached_environment.rb:44:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/bundle.rb:41:in `block in call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/utils.rb:167:in `dfs'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/bundle.rb:42:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:145:in `load_from_unloaded'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:59:in `block in load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:329:in `fetch_asset_from_dependency_cache'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:43:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/cached_environment.rb:44:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/source_map_processor.rb:31:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:145:in `load_from_unloaded'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:59:in `block in load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:329:in `fetch_asset_from_dependency_cache'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:43:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/cached_environment.rb:44:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/bundle.rb:32:in `block in call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/bundle.rb:31:in `call'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:84:in `call_processor'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:66:in `block in call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `reverse_each'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/processor_utils.rb:65:in `call_processors'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:145:in `load_from_unloaded'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:59:in `block in load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:329:in `fetch_asset_from_dependency_cache'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/loader.rb:43:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/cached_environment.rb:44:in `load'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/base.rb:81:in `find_asset'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/base.rb:88:in `find_all_linked_assets'
/Users/vision/.rvm/gems/ruby-2.5.3/bundler/gems/sprockets-aff8e74108b8/lib/sprockets/manifest.rb:125:in `block (2 levels) in find'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/safe_task_executor.rb:24:in `block in execute'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/synchronization/mutex_lockable_object.rb:41:in `block in synchronize'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/synchronization/mutex_lockable_object.rb:41:in `synchronize'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/safe_task_executor.rb:19:in `execute'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/promise.rb:563:in `block in realize'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:348:in `run_task'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:337:in `block (3 levels) in create_worker'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `loop'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:320:in `block (2 levels) in create_worker'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `catch'
/Users/vision/.rvm/gems/ruby-2.5.3/gems/concurrent-ruby-1.1.3/lib/concurrent/executor/ruby_thread_pool_executor.rb:319:in `block in create_worker'
Tasks: TOP => assets:precompile

System configuration

I tried to create an example app, but I couldn't seem to replicate the problem just by adding files (at least none that weren't my real production files, which my work hasn't allowed me to share).

CodingAnarchy commented 5 years ago

There are *.coffee and *.js.jsx files in the app/assets/javascripts directory tree, but I tried that with the example app without issue, so it is unclear to me whether that matters.

r7kamura commented 4 years ago

In my case, //= in coffee-script file caused a similar error on sprockets v4.0.0.

# app/assets/javascripts/foo.js.coffee
//= require jquery
ExecJS::ProgramError: SyntaxError: [stdin]:1:1: unexpected //=                                                                                             compile ((execjs):7528:19)
(execjs):1:10                                                                                                                                              /usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:201:in `eval_unsafe'
/usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:201:in `block (2 levels) in eval'
/usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:286:in `timeout'                                                                                 /usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:200:in `block in eval'
/usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:198:in `synchronize'                                                                             /usr/local/bundle/gems/mini_racer-0.2.6/lib/mini_racer.rb:198:in `eval'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/mini_racer_runtime.rb:27:in `block in eval'                                                                 /usr/local/bundle/gems/execjs-2.7.0/lib/execjs/mini_racer_runtime.rb:66:in `translate'
/usr/local/bundle/gems/execjs-2.7.0/lib/execjs/mini_racer_runtime.rb:26:in `eval'                                                                          /usr/local/bundle/gems/execjs-2.7.0/lib/execjs/mini_racer_runtime.rb:34:in `call'
/usr/local/bundle/gems/coffee-script-2.4.1/lib/coffee_script.rb:78:in `compile'                                                                            /usr/local/bundle/gems/sprockets-4.0.0/lib/sprockets/coffee_script_processor.rb:24:in `block in call'
/usr/local/bundle/gems/sprockets-4.0.0/lib/sprockets/cache.rb:92:in `fetch'                                                                                /usr/local/bundle/gems/sprockets-4.0.0/lib/sprockets/coffee_script_processor.rb:23:in `call'
...

and this error was fixed by replacing //= with #= like this:

# app/assets/javascripts/foo.js.coffee
#= require jquery