hsume2 / browserify-rails

Deprecated https://github.com/browserify-rails/browserify-rails
MIT License
57 stars 11 forks source link

'rake assets:precompile' not functioning properly #30

Open hhutch opened 10 years ago

hhutch commented 10 years ago

Steps to reproduce:

  1. default configuration options for browserify-rails
  2. all node modules in ROOT/node_modules with ROOT/package.json
  3. all JSX/React code in ROOT/app/assets/javascripts
  4. App functions properly in develop mode
  5. change config/environments/development.rb to 'config.assets.debug = true'
  6. run
rake assets:precompile RAILS_ENV=development

RESULT: browserify does not compile into a single JS asset and individual JS files (such as React libraries) are loaded but throw errors

Please let me know if I am making some sort of mistake, but as of now I have to revert to manual compilation as recommended in issue #27

martenlienen commented 10 years ago

assets:precompile should be run in production environment, so RAILS_ENV=production rake assets:precompile or simply rake assets:precompile, because this task uses the production environment by default, I think.

Does this fix it?

hhutch commented 10 years ago

I get the same error running precompiled assets in both production and development modes. I am attempting to deploy to Heroku. Running with browserify-rails in development, not recompiling assets, works well.

I am using both NPM installed node_modules and writing many of my own components for use in a React UI.

msernatinger commented 10 years ago

Hi. I'm having this very same issue on Rails 3.2.17. What I am observing is that the Rails engine is not being registered when I run rake assets:precompile. It works fine with development-mode runtime asset compilation.

It's also not clear from the Readme which versions of Rails are supported. I would guess at least 3.2 and up?

michael-ns commented 10 years ago

It works fine when I run RAILS_ENV=production rake assets:precompile on my local. But it throw the following error message when I push to heroku master:

   Cleaning up the bundler cache. 

-----> Using Node.js version: 0.10.21 -----> Installing JavaScript dependencies using Bower 1.3.9 bower moment#* cached git://github.com/moment/moment.git#2.8.3 bower moment#* validate 2.8.3 against git://github.com/moment/moment.git#* bower moment#* install moment#2.8.3
moment#2.8.3 bower_components/moment
Cleaning up the bower tmp. -----> Preparing app for Rails asset pipeline Running: rake assets:precompile rake aborted! BrowserifyRails::BrowserifyError: browserify could not be found at /tmp/build_150c72a7-cb5c-425c-99d0-1fdafc780a27/./node_modules/.bin/browserify. Please run npm install. (in /tmp/build_150c72a7-cb5c-425c-99d0-1fdafc780a27/app/assets/javascripts/components.js)

ikido commented 9 years ago

I've got same error as michael-ns when pushing to heroku. If I include node-modules folder into the repo I get Errno::EPIPE: Broken pipe error. Any suggestions?

As a workaround you can disable asset compilation for production and sync manually with rake assets:precompile RAILS_ENV=production

joaovpmamede commented 9 years ago

I'm having the same problem.

Currently doing what @ikido suggested and it works but it's not the ideal.

chikathreesix commented 9 years ago

I had same issue as @michael-ns and found the solution. Here is what I did. http://ryochikazawa.com/2015/01/30/heroku-with-browserify-rails.html

joaovpmamede commented 9 years ago

@chikathreesix thanks a lot for finding the solution to this. Anyway, when you write:

Create .buildpack file for the multi-buildpack to make sure node.js is compiled before ruby.

I think the file has to be named .buildpacks instead of .buildpack (http://stackoverflow.com/a/14801582)

chikathreesix commented 9 years ago

@joaovpmamede thank you for pointing this out. Yeah, you're correct. I've fixed the blog post.

kfamilonidis commented 8 years ago

Hello I have the same issue with this output and rails setup https://gist.github.com/kfamilonidis/e21e2b7e088732e684fb I haven't found any resolution yet other than to manually run.

NODE_VERSION=v5.0.0 RAILS_ENV=production /usr/local/rvm/bin/rvm default do bundle exec rake assets:precompile

=== UPDATE

solved - I replaced the double quotes with single ones on the browserify parameters and worked!

config.browserify_rails.commandline_options = "--transform reactify --extension='.jsx'"

insead of

config.browserify_rails.commandline_options = "--transform reactify --extension=\".jsx\" ".
hsume2 commented 8 years ago

@kfamilonidis It's awesome that you found a fix for this issue, thanks! Active development for browserify-rails has actually moved to https://github.com/browserify-rails/browserify-rails, so it'd be great if you could share your findings there :)