Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rake assets:precompile doesn't work when using ES6 on Heroku #137

Open
Rodrigora opened this issue Feb 3, 2016 · 33 comments
Open

rake assets:precompile doesn't work when using ES6 on Heroku #137

Rodrigora opened this issue Feb 3, 2016 · 33 comments

Comments

@Rodrigora
Copy link

Hey Guys,

I'm struggling to precompile my Javascript files. I already tried the solutions of #133 and #132.

To exemplify the issue, I created this app. It is a
"empty" rails app with browserify-rails gem and 1 JS file using ES6 syntax.

Some relevant files:

package.json

{
  "name": "something",
  "dependencies" : {
    "browserify": "~> 10.2.4",
    "browserify-incremental": "^3.0.1",
    "babelify": "^7.2.0"
  },
  "license": "MIT",
  "engines": {
    "node": ">= 0.10"
  }
}

config/application.rb

config.browserify_rails.commandline_options = "-t babelify --extension-'.jsx'"

app/assets/javascripts/components/hello.jsx

"use strict";

class Hello {
  constructor() {
    $(window).ready(function() {
      $('body').append('Hello es6!');
    });
  }
}
module.exports = Hello;

I'm using jsx extension because I intend to add react to this project

The error is:

ExecJS::ProgramError: Unexpected token: name (Hello) (line: 11569, col: 6, pos: 326687)

Error
    at new JS_Parse_Error (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:11936)
    at js_error (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:12155)
    at croak (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:20622)
    at token_error (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:20759)
    at unexpected (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:20847)
    at semicolon (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:21320)
    at simple_statement (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:24179)
    at /private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:22152
    at /private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:21493
    at block_ (/private/var/folders/xt/853lxmvx7yx2w8v4xyc92t4h0000gn/T/execjs20160203-74579-14fk3xfjs:2659:26198)
  (in /Users/rodrigora/Projects/browserify_test/app/assets/javascripts/application.js)new JS_Parse_Error ((execjs):2659:11936)
js_error ((execjs):2659:12155)
croak ((execjs):2659:20622)
token_error ((execjs):2659:20759)
unexpected ((execjs):2659:20847)
semicolon ((execjs):2659:21320)
simple_statement ((execjs):2659:24179)
(execjs):2659:22152
(execjs):2659:21493
block_ ((execjs):2659:26198)
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:39:in `exec'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:21:in `eval'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/execjs-2.6.0/lib/execjs/external_runtime.rb:46:in `call'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/uglifier-2.7.2/lib/uglifier.rb:212:in `run_uglifyjs'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/uglifier-2.7.2/lib/uglifier.rb:179:in `compile'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/uglifier_compressor.rb:25:in `evaluate'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/context.rb:194:in `each'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/context.rb:194:in `evaluate'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/bundled_asset.rb:25:in `initialize'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/base.rb:377:in `new'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/base.rb:377:in `build_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/index.rb:93:in `build_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/base.rb:287:in `find_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/index.rb:61:in `find_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:118:in `each'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/sprockets/manifest.rb:118:in `compile'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-2.12.4/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/gems/sprockets-rails-2.3.3/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/bin/ruby_executable_hooks:15:in `eval'
/Users/rodrigora/.rvm/gems/ruby-2.2.4@browserfy/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
@cymen
Copy link
Member

cymen commented Feb 3, 2016

Do you have browserify-rails in your production environment too (in Gemfile)? If not...

@cymen
Copy link
Member

cymen commented Feb 3, 2016

Oh, I checked your example and it looks like it is in all envs. So it's not that.

@cymen
Copy link
Member

cymen commented Feb 3, 2016

I don't know if we support the .jsx extension -- try changing that to .js and see if it works. You don't need .jsx for React (it'll work fine with .js -- which is what I use on my non-browserify-rails React code and is common).

@Rodrigora
Copy link
Author

Hey @cymen,

yep, this error ocurrs when try to deploy to heroku.

Same error with js extension

@cymen
Copy link
Member

cymen commented Feb 3, 2016

So can you run RAILS_ENV=production bundle exec rake assets:precompile successfully on local?

Have you done this part: https://github.com/browserify-rails/browserify-rails#deploying-to-heroku

@Rodrigora
Copy link
Author

Yep @cymen.

My heroku buildpacks are setup (nodejs before ruby).

Yes, I get this error both in Heroku and when running RAILS_ENV=production bundle exec rake assets:precompile locally.

Have no idea why it works in developement mode

@cymen
Copy link
Member

cymen commented Feb 3, 2016

I can't spend more time on it at the moment but if you comment out the line for this:

config.assets.js_compressor = ...

In config/environments/production.rb that'll make it work. At least it did for me w/ upgraded gems but should work even w/o upgraded gems. Not sure what is going on though. It might be that by using .js with ES6, it goes through uglify too early -- maybe try using the .es6 extension as mentioned in the README of this project (I don't use that option so not sure).

@Rodrigora
Copy link
Author

Thanks @cymen

Yes, with the js_compressor line commented, it works, but the files won't be minified.

Will try the .es6 extension

@Rodrigora
Copy link
Author

Hey,

this is related to recent babel changes. Better explained here: http://stackoverflow.com/questions/35178096/how-to-configure-a-rails-app-with-es6-support

I had to add babel-preset-es2015 module to my package.json and changed browserify options:

config.browserify_rails.commandline_options = "-t [ babelify --presets [ es2015 ] ]"

@cymen I can a create a PR updating the README if you think this is relevant

@cymen
Copy link
Member

cymen commented Feb 10, 2016

@Rodrigora Excellent -- thanks for figuring it out. A PR for the README would be great.

@jamesfzhang
Copy link

I've followed the instructions and I'm having trouble getting this to work in production with react. I'm getting this error:

remote:        BrowserifyRails::BrowserifyError: Error while running `/tmp/build_3676ad6cb87a6ef8e94ae3b95727c78b/node_modules/.bin/browserify -t [ babelify --presets [ es2015 react ] ] --list -o "/tmp/build_3676ad6cb87a6ef8e94ae3b95727c78b/tmp/cache/browserify-rails/output20160217-711-1wkt1fr" -`:
remote:        events.js:154
remote:        throw er; // Unhandled 'error' event
remote:        ^
remote:        Error: Cannot find module 'React' from '/tmp/build_3676ad6cb87a6ef8e94ae3b95727c78b/app/assets/javascripts/v2/components'

Heres my configs:

config.browserify_rails.commandline_options = '-t [ babelify --presets [ es2015 react ] ]'
{
  "name": "theartistunion",
  "dependencies": {
    "alt": "^0.18.2",
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0",
    "babelify": "^7.2.0",
    "browserify": "~> 10.2.4",
    "browserify-incremental": "^3.0.1",
    "classnames": "^2.2.3",
    "es6-promise": "^3.0.2",
    "history": "^1.17.0",
    "jquery": "^2.2.0",
    "minigrid": "^2.2.0",
    "nprogress": "^0.2.0",
    "react": "^0.14.7",
    "react-addons-update": "^0.14.7",
    "react-cookie": "^0.4.3",
    "react-dom": "^0.14.7",
    "react-router": "^1.0.3",
    "react-select": "^0.9.1",
    "react-timer-mixin": "^0.13.3",
    "shitty-qs": "^1.0.1",
    "soundmanager2": "^2.97.20150601",
    "superagent": "^1.7.2",
    "underscore": "^1.8.3",
    "wallop": "git://github.com/jamesfzhang/wallop.git",
    "whatwg-fetch": "^0.11.0"
  },
  "license": "MIT",
  "engines": {
    "node": ">= 0.10",
    "npm": "2.14.7"
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0"
  }
}

Works fine locally but assets can't finish precompiling on Heroku ( I have the nodejs & ruby buildpacks).

@cymen
Copy link
Member

cymen commented Feb 17, 2016

@jamesfzhang I think you need to move those two dev dependencies to regular dependencies as your build on Heroku is probably production not dev. So move these two lines up into dependencies:

    "babel-preset-es2015": "^6.5.0",
    "babel-preset-react": "^6.5.0"

@jamesfzhang
Copy link

@cymen Good catch, but those presets are actually in dependencies as well.

@cymen
Copy link
Member

cymen commented Feb 17, 2016

Ah, I missed that. Hrm...

@jamesfzhang
Copy link

Here's the full error:

remote:        D, [2016-02-17T22:25:33.362782 #711] DEBUG -- : Browserify: /tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/.bin/browserify -t [ babelify --presets [ es2015 react ] ] --list -o "/tmp/build_336aa416a5618553366a6bcaa09a80dc/tmp/cache/browserify-rails/output20160217-711-1r7v268" -
remote:        I, [2016-02-17T22:25:46.498386 #711]  INFO -- : [Rollbar] Scheduling payload
remote:        I, [2016-02-17T22:25:46.498462 #711]  INFO -- : [Rollbar] Sending payload
remote:        I, [2016-02-17T22:25:46.688815 #711]  INFO -- : [Rollbar] Success
remote:        I, [2016-02-17T22:25:46.688918 #711]  INFO -- : [Rollbar] Details: https://rollbar.com/instance/uuid?uuid=b35fb98f-da38-4a67-9509-9045e326458d (only available if report was successful)
remote:        rake aborted!
remote:        BrowserifyRails::BrowserifyError: Error while running `/tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/.bin/browserify -t [ babelify --presets [ es2015 react ] ] --list -o "/tmp/build_336aa416a5618553366a6bcaa09a80dc/tmp/cache/browserify-rails/output20160217-711-1r7v268" -`:
remote:        events.js:154
remote:        throw er; // Unhandled 'error' event
remote:        ^
remote:        Error: Cannot find module 'React' from '/tmp/build_336aa416a5618553366a6bcaa09a80dc/app/assets/javascripts/v2/components'
remote:        at /tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
remote:        at process (/tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
remote:        at ondir (/tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
remote:        at load (/tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
remote:        at onex (/tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
remote:        at /tmp/build_336aa416a5618553366a6bcaa09a80dc/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
remote:        at FSReqWrap.oncomplete (fs.js:82:15)
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:210:in `run_browserify'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:138:in `dependencies'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:115:in `commonjs_module?'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:87:in `should_browserify?'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:33:in `call'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/browserify-rails-2.2.1/lib/browserify-rails/browserify_processor.rb:15:in `call'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in `block in load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:44:in `load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `yield'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/bundle.rb:23:in `block in call'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/utils.rb:183:in `dfs'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/bundle.rb:24:in `call'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in `block in load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:44:in `load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:20:in `block in initialize'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `yield'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/cached_environment.rb:47:in `load'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/base.rb:66:in `find_asset'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/base.rb:73:in `find_all_linked_assets'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:142:in `block in find'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:225:in `block in stat_tree'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:209:in `block in stat_directory'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:206:in `each'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:206:in `stat_directory'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/path_utils.rb:224:in `stat_tree'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:105:in `each'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:105:in `block in logical_paths'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:104:in `each'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/legacy.rb:104:in `logical_paths'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:140:in `find'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/sprockets/manifest.rb:168:in `compile'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-3.5.2/lib/rake/sprocketstask.rb:147:in `with_logger'
remote:        /tmp/build_336aa416a5618553366a6bcaa09a80dc/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
remote:        Tasks: TOP => assets:precompile

@cymen
Copy link
Member

cymen commented Feb 17, 2016

@jamesfzhang Unfortunately, I don't know. If your immediate goal is to be able to deploy, it might be worth precompiling the assets locally, committing them and making it so Heroku doesn't try to compile them. Just to get it working now. You can precompile them locally by running:

bundle exec rails assets:precompile RAILS_ENV=production

That is by memory so good to verify. Then commit public/assets -- that might be enough to prevent Heroku from trying to precompile (I'd commit and push to Heroku and see -- if not, should be some documentation on how to disable it).

That is not ideal but at least you would not be blocked.

@cymen cymen reopened this Feb 17, 2016
@jamesfzhang
Copy link

Thanks @cymen for the suggestion, I'll do that until we figure out what's going on here.

@dlackty
Copy link

dlackty commented Feb 18, 2016

If you're using Browserify not only for modules but also using transformers like babelify, you need to make sure every file that need to be transformed (e.g. from ES6) is properly wrapped into module by adding module.exports.

@cymen
Copy link
Member

cymen commented Feb 18, 2016

@dlackty Yes, that is a good point. I recommend having one initial starting module so it would look something like:

application.js:

//= require something-crufty
var bootstrap = require('./bootstrap');
bootstrap();

bootstrap.js -- do not use any sprocket requires (//= ... kind of things) in any code at or below bootstrap):

module.exports = function bootstrap() {
  // start your application here
};

That avoids having to do anything hacky in my experience. The goal being to get pulled in via sprockets for the asset pipeline but using CommonJS for the rest of the application. If you want some non-CommonJS code, pull it in via application.js and it'll be in the normal global (Rails) approach.

@cymen
Copy link
Member

cymen commented Feb 18, 2016

(it can be multiple modules but mastering one module first is a good start)

@jamesfzhang
Copy link

Here's my application.js:

//= require turbolinks
require('v2/application');

Here's v2/application.js

'use strict';

require('bootstrap');
require('whatwg-fetch');
require('es6-promise').polyfill();

var React = require('react');
var ReactDOM = require('react-dom');
var routes = require('./routes');

$(document).ready(function() {
  ReactDOM.render(routes, document.getElementById('app'));
});

Every file required by routes from here on has module.exports. I'll try wrapping my v2/application.js in module.exports to see if that fixes the problem.

@jamesfzhang
Copy link

Still running into the same error.

// application.js
let application = require('v2/application');
application();
// v2/application.js
'use strict';

require('bootstrap');
require('whatwg-fetch');
require('es6-promise').polyfill();

var React = require('react');
var ReactDOM = require('react-dom');
var routes = require('./routes');

module.exports = function() {
  $(document).ready(function() {
    ReactDOM.render(routes, document.getElementById('app'));
  });
};

@cymen cymen changed the title rake assets:precompile doesn't work when using ES6 rake assets:precompile doesn't work when using ES6 on Heroku Feb 27, 2016
@mockdeep
Copy link
Contributor

mockdeep commented Mar 2, 2016

We're seeing similar issues and tracked it down to the uglifier. When we copied the uglifier setting from production.rb to development.rb and ran rake assets:precompile we saw the same error. In our case it turns out it was because we had the es2015 setting in our package.json file, but added reactify to the commandline_options inside application.rb, which we didn't realize would override the settings in package.json. We got past that, and are now seeing another error:

Error: Couldn't find preset "es2015" relative to directory "/home/fletch/.rvm/gems/ruby-2.2.4/gems/rails-assets-jquery-1.10.0/app/assets/javascripts" while parsing file: /home/fletch/.rvm/gems/ruby-2.2.4/gems/rails-assets-jquery-1.10.0/app/assets/javascripts/jquery.js
    at OptionManager.mergePresets (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/option-manager.js:327:17)
    at OptionManager.mergeOptions (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/option-manager.js:287:12)
    at OptionManager.init (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/file/options/option-manager.js:416:10)
    at File.initOptions (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/file/index.js:190:75)
    at new File (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/file/index.js:121:22)
    at Pipeline.transform (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/node_modules/babel-core/lib/transformation/pipeline.js:42:16)
    at Babelify._flush (/home/fletch/Dropbox/projects/chalk/synchroform/node_modules/babelify/index.js:28:24)
    at Babelify.<anonymous> (_stream_transform.js:118:12)
    at Babelify.g (events.js:260:16)
    at emitNone (events.js:67:13)
    at Babelify.emit (events.js:166:7)

@cymen
Copy link
Member

cymen commented Mar 3, 2016

@mockdeep Why is a jQuery file from a gem being browserified? Did you try to do a //= require jquery or some such inside of a file that would also be browserified? If so, you're likely going to have a bad time. Either use CommonJS jQuery or put jQuery sprocket call (//=) in the top file or a separate file.

I suspect the issue is trying to use gems for JavaScript assets -- if you're going to use CommonJS, it's a good idea to stop using gems that package JavaScript files.

@mockdeep
Copy link
Contributor

mockdeep commented Mar 3, 2016

@cymen We're gradually moving our assets over to browserify, but still have some references to gem assets. I found a couple places where we have sprockets requires and a module.exports in the same file, so will try switching those out and see what happens. Neither seems to be related to rails-assets-jquery, though. Odd that it only becomes a problem when we try to pipe it through babelify, though.

@cymen
Copy link
Member

cymen commented Mar 3, 2016

@mockdeep That is really odd. In general, I've found the best approach is to have one file that does any sprocket requires at the top and then does a CommonJS require (or import now w/ browserify-rails 3.0.1) and from that CommonJS module down, stay with CommonJS and try not to mix in sprockets -- trying to blend it does cause issues.

Another approach is to have a core bundle with all the sprockets-required JavaScript and separate bundle for CommonJS. Not a huge difference technically.

@mockdeep
Copy link
Contributor

mockdeep commented Mar 3, 2016

Yeah, we're basically taking that approach, though a couple of files slipped through. It doesn't actually seem to be causing any other issues, though, surprisingly.

@cymen
Copy link
Member

cymen commented Mar 3, 2016

Ah! That is good to know. When I was using this gem daily (prior employment, not needed in current employment), we ran into issues early and went that route so I don't have much experience mixing the two.

@rloomba
Copy link

rloomba commented May 2, 2016

@jamesfzhang did you ever figure out what's going on? Cannot get my app deployed to Heroku :(

"dependencies": {
    "react": "^0.14.2",
    "react-dom": "^0.14.2",
    "react-redux": "^4.0.0",
    "redux": "^3.0.4",
    "redux-thunk": "^1.0.0",
    "moment": "^2.13.0",
    "attachmediastream": "^1.3.5",
    "browserify": "^10.2.4",
    "browserify-incremental": "^3.0.1",
    "babelify": "^7.2.0",
    "babel-preset-es2015": "^6.1.2",
    "babel-preset-react": "^6.1.2",
    "babel-preset-stage-2": "^6.1.2"
  }

config.browserify_rails.commandline_options ="-t [ babelify --presets [ es2015 ] ]"

remote:        Browserify: /tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/.bin/browserify -t [ babelify --presets [ es2015 ] ] --list -o "/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/tmp/cache/browserify-rails/output20160502-544-8v9ab1" -
remote:        rake aborted!
remote:        BrowserifyRails::BrowserifyError: Error while running `/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/.bin/browserify -t [ babelify --presets [ es2015 ] ] --list -o "/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/tmp/cache/browserify-rails/output20160502-544-8v9ab1" -`:
remote:        events.js:154
remote:        throw er; // Unhandled 'error' event
remote:        ^
remote:        SyntaxError: /tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/app/assets/javascripts/components/containers/Room.js: Unexpected token (161:6)
remote:        159 |   render() {
remote:        160 |     return (
remote:        > 161 |       <div>
remote:        |       ^
remote:        162 |         <LocalVideoContainer/>
remote:        163 |         <h2>
remote:        164 |           Hi
remote:        at Parser.pp.raise (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:1378:13)
remote:        at Parser.pp.unexpected (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:2817:8)
remote:        at Parser.pp.parseExprAtom (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:749:12)
remote:        at Parser.pp.parseExprSubscripts (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:504:19)
remote:        at Parser.pp.parseMaybeUnary (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:484:19)
remote:        at Parser.pp.parseExprOps (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:415:19)
remote:        at Parser.pp.parseMaybeConditional (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:397:19)
remote:        at Parser.pp.parseMaybeAssign (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:360:19)
remote:        at Parser.pp.parseParenAndDistinguishExpression (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:822:26)
remote:        at Parser.pp.parseExprAtom (/tmp/build_2adb9fb138a87454ba2552f74bfa2ecd/node_modules/babylon/index.js:708:19)

@Rodrigora
Copy link
Author

Hey @rloomba,

are you using the react-rails gem?

If not, change the command lines options to this:

config.browserify_rails.commandline_options ="-t [ babelify --presets [ es2015 react ] ]"

@mockdeep
Copy link
Contributor

mockdeep commented May 2, 2016

Yeah, looks like you don't have a processor to handle jsx in there. Not sure if the order matters, but you may need to do [ react es2015 ], with react first.

@rloomba
Copy link

rloomba commented May 2, 2016

yeah I am using the react-rails gem

@Rodrigora @mockdeep thanks for the help guys, this works! 🙏

@DaltheCow
Copy link

I can't spend more time on it at the moment but if you comment out the line for this:

config.assets.js_compressor = ...

In config/environments/production.rb that'll make it work. At least it did for me w/ upgraded gems but should work even w/o upgraded gems. Not sure what is going on though. It might be that by using .js with ES6, it goes through uglify too early -- maybe try using the .es6 extension as mentioned in the README of this project (I don't use that option so not sure).

Is it bad to do this? I had to do this to get a heroku deploy to go through

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants