emberjs / ember-rails

Ember for Rails 3.1+
https://github.com/emberjs/ember-rails
MIT License
1.36k stars 251 forks source link

ExecJS::ProgramError: Unexpected token: punc (:) due to ember-data.js.map #428

Open ur5us opened 9 years ago

ur5us commented 9 years ago

After upgrading to version 0.16.1 the build consistently fails, that is, I'm not able to run bundle exec rake assets:precompile successfully. Here's the stack trace which suggests that there is an issue with ember-data.js.map:

rake aborted!
ExecJS::ProgramError: Unexpected token: punc (:) (line: 1, col: 10, pos: 10)

Error
    at new JS_Parse_Error (<eval>:2359:10623)
    at js_error (<eval>:2359:10842)
    at croak (<eval>:2359:19086)
    at token_error (<eval>:2359:19223)
    at unexpected (<eval>:2359:19311)
    at semicolon (<eval>:2359:19784)
    at simple_statement (<eval>:2359:22580)
    at <eval>:2359:20274
    at <eval>:2359:19957
    at block_ (<eval>:2359:24599)
  (in /Users/ur5us/dev/haka_tours/tmp/ember-rails/ember-data.js.map)/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:34:in `rescue in block in eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:28:in `block in eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:78:in `block in lock'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `call'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `Locker'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `lock'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:27:in `eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:19:in `exec'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/uglifier-2.6.1/lib/uglifier.rb:200:in `run_uglifyjs'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/uglifier-2.6.1/lib/uglifier.rb:178:in `compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.21/lib/sprockets/compressors.rb:74:in `compress'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.21/lib/sprockets/compressors.rb:74:in `compress'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processing.rb:265:in `block in js_compressor='
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `call'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:193:in `block in evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:24:in `initialize'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:41:in `block in compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:219:in `block in each_logical_path'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each_entry'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:204:in `block in each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:217:in `each_logical_path'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
V8::Error: Unexpected token: punc (:)
at js_error (<eval>:2359:10842)
at croak (<eval>:2359:19086)
at token_error (<eval>:2359:19223)
at unexpected (<eval>:2359:19311)
at semicolon (<eval>:2359:19784)
at simple_statement (<eval>:2359:22580)
at <eval>:2359:20274
at <eval>:2359:19957
at block_ (<eval>:2359:24599)
at <eval>:2359:20663
at <eval>:2359:19957
at <eval>:2359:31968
at parse (<eval>:2360:152)
at <eval>:19:24
at <eval>:62:3
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:29:in `block in eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:78:in `block in lock'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `call'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `Locker'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:76:in `lock'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:27:in `eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/execjs-2.2.2/lib/execjs/ruby_racer_runtime.rb:19:in `exec'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/uglifier-2.6.1/lib/uglifier.rb:200:in `run_uglifyjs'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/uglifier-2.6.1/lib/uglifier.rb:178:in `compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.21/lib/sprockets/compressors.rb:74:in `compress'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/actionpack-3.2.21/lib/sprockets/compressors.rb:74:in `compress'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processing.rb:265:in `block in js_compressor='
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `call'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/processor.rb:29:in `evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:193:in `block in evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `evaluate'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:24:in `initialize'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:41:in `block in compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:219:in `block in each_logical_path'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each_entry'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:204:in `block in each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each_file'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/sprockets-2.2.3/lib/sprockets/base.rb:217:in `each_logical_path'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
Tasks: TOP => assets:precompile:all
(See full trace by running task with --trace)
rake aborted!
Command failed with status (1): [/Users/ur5us/.rvm/rubies/ruby-2.1.5/bin/ru...]
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:24:in `ruby_rake_task'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:33:in `invoke_or_reboot_rake_task'
/Users/ur5us/.rvm/gems/ruby-2.1.5/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:50:in `block (2 levels) in <top (required)>'
/Users/ur5us/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'
/Users/ur5us/.rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)

Even more annoyingly I can't just downgrade the gem via specifying version 0.16.0 in the Gemfile, at least not until I manually execute rm -rf tmp/ember-rails/.

Potentially related: #343 #357

rgrinberg commented 9 years ago

Are there any workarounds for this?

@ur5us what version of rails are you using?

ur5us commented 9 years ago

@rgrinberg I'm currently on 3.2.21. I think the problem might be that the asset pipeline tries to compile the map (TBC).

tricknotes commented 9 years ago

I changed the way to manage bundled files https://github.com/emberjs/ember-rails/pull/448. Then it stop copying ember-data.js.map to tmp/ember-rails.

I think it will fix this issue. Could you try using ember-rails@0.16.4 after cache cleared. If it doesn't please ping me.

ur5us commented 9 years ago

@tricknotes I've upgraded us to ember-rails@0.16.4 but the error still happens. It doesn't matter whether the file is copied or not. What matters is that it's in the Sprockets path which it seems to be. Thus, I'm using the following solution: /cc @rgrinberg

config/initializers/rack.rb:

Rack::Mime::MIME_TYPES.merge!({".map" => "text/plain"})

Further details here: https://github.com/jamesotron/faye-rails/issues/15#issuecomment-6692493.

ur5us commented 9 years ago

@tricknotes I'm not entirely sure whether this is a problem with ember-rails, Rails (asset pipeline), Sprockets or even something else. I'm happy to close this issue but add a note to the docs.

tjgfernandes commented 9 years ago

thank you @tricknotes , adding MIME_TYPES worked for me, i'm using ember-rails@0.16.3

dariusgm commented 9 years ago

Fix: Remove this file from the asset pipeline, because it is not valid JavaScript. Add Stuff like this to your application.rb

module App class Application < Rails::Application ... file_ext_exclude = ['.map'] ... end end

caseyli commented 9 years ago

Modifying the default rails definition for assets.precompile in production.rb did it for me:

config.assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css', '.map']) }, /(?:\/|\\|\A)application\.(css|js)$/]

I also had a separate manifest for my ember app so it looked like this:

config.assets.precompile = [ Proc.new{ |path| !File.extname(path).in?(['.js', '.css', '.map']) }, /(?:\/|\\|\A)application\.(css|js)$/, "ember_apps.js" ]

Found that answer here: http://stackoverflow.com/a/10099659

However, note that my asset precompilation took forever on Heroku and I noticed that things were being precompiled more than once. So there might be some issue with this workaround.

hernanvicente commented 8 years ago

I had the same problem when I've deployed to heroku. I've changed the syntax in my code from:

I'm actually a noob with Ember and I didn't want to change many things in my rails config. It's worth saying the ember code in my application is small.

Later I found the same solution here: http://stackoverflow.com/a/32534114/642496

My question: Is this a valid/good solution? Is there a negative impact on app performance or for me as developer? Thanks!

baraka2000 commented 8 years ago

I hit this problem and have tried all the above work arounds with no luck. What's worse is I'm not even using ember data. Can ember-data be removed somehow??

ur5us commented 8 years ago

@hernanvicente It's the same. The former is ES6 syntax, the latter E3/5. It looks like it's related to the uglifier gem: http://stackoverflow.com/questions/30422437/execjsprogramerror-unexpected-token-punc-expected-punc-when-running/32534114#comment50344169_30422437

@baraka2000 It's hard to tell without further details but the following might help (still using my solution above and assuming your issue happens in dev mode?):

# make sure you stop your rails server, especially if you're using spring app preloader, then
bundle exec rake tmp:cache:clear

In your Gemfile, you might try the following:

gem 'ember-rails'
gem 'ember-data-source', require: false

Start your server and try again.