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

not compiling on production after update to browserify 14.3.0 #202

Open
jefree opened this issue May 29, 2017 · 9 comments
Open

not compiling on production after update to browserify 14.3.0 #202

jefree opened this issue May 29, 2017 · 9 comments

Comments

@jefree
Copy link

jefree commented May 29, 2017

I have update the browser package version to 14.3.0 and it seems to not be compiling the files correctly, on rake assets:precompile everything looks fine, no errors, but after launch the app and go to the page i'm using some JS i'm getting ReferenceError: MyComponent is not defined, but if i come back to previous version (13.3.0), and precompile, everything works fine.

It is just failing at production mode, in development it works as expected.

I've tried to look for the Component declaration within the compiled files and it doesn't appears anywhere, but in the development compiled version it does.

@alekseyg
Copy link

alekseyg commented Jun 9, 2017

I'm having the same issue. In production and staging, all of the files being processed through browserify come out empty with browserify 14.1.0+. I tried 13.3.0-14.4.0 and it worked with 13.3.0 and 14.0.0, but everything above that failed.

Another thing is this problem only appears in the newer versions of browserify if browserify-incremental is disabled. Enabling it makes browserify-rails work with the latest browserify. You can do this by putting the following line in production/staging.rb

  config.browserify_rails.use_browserifyinc = true

config.browserify_rails.use_browserifyinc = !["staging", "production"].include?(Rails.env)

@alekseyg
Copy link

alekseyg commented Jun 9, 2017

The pull request for browserify 14.1.0 has this comment, which might have something to do with this issue: browserify/browserify#1673 (comment)

@alekseyg
Copy link

alekseyg commented Jun 10, 2017

As of v3.1.0, browserify-incremental no longer requires fullPaths, so enabling it on production and staging is safe now, at least according to my tests.
jsdf/browserify-incremental#25

@cymen
Copy link
Member

cymen commented Jun 10, 2017

It might also be that the piping mode of browserify is broken. Last time it broke (a couple years ago), I submitted a PR for the bug. substack suggested maybe doing a test for it too but there were more pressing issues and (this reminded me) it never got done. So first thing I'd do is pull down the new browserify and do some basic manual tests of piping a module in and making sure it emits the expected output.

@avit
Copy link

avit commented Nov 28, 2017

I ran into this as well. It looks like browserify is expecting to find .js files under app/assets. Running browserify manually shows an error:

Error: Cannot find module 'yes/it/exists' from '/app/app/assets/javascripts'

Since browserifyinc fixes this, I suspect that these are compiled into the cache and then found there. Otherwise it's looking for .js files, but there are only .coffee, .jsx, etc. files in the source location.

In addition to fixing the compilation issue, it should not fail silently on similar errors when running browserify and it gives exit status 1.

@cymen
Copy link
Member

cymen commented Nov 28, 2017

@avit That might be a browserify-rails configuration issue and not an issue with browserify itself. Are you adding the additional paths to config.browserify_rails.paths? That is if they are outside of app. The default paths are added here:

https://github.com/browserify-rails/browserify-rails/blob/master/lib/browserify-rails/railtie.rb#L10-L12

@avit
Copy link

avit commented Nov 28, 2017

@cymen, no, these are not outside of app/assets. Just adding use_browserifyinc = true made it work so I'm only speculating about the reason based on that.

My file looked like this (js.coffee):

#= require one
#= require_tree two
#= require_self

window.GlobalThing =
  Builder: require('three')

The output included items one and two, but silently ignored everything from require_self. If the file does not contain any require statements in the body, then the output is included. It seems to fail silently when require() is used.

So, possibly something about the build order and those files not being compiled first as dependencies?

@cymen
Copy link
Member

cymen commented Nov 28, 2017

Hrm.. That is odd. My recommended approach is to put all of the code that uses CommonJS in one entry point that gets required via the sprockets require calls. If there are multiple entry points into CommonJS, it seems like it can cause problems.

But I never looked into it in greater depth so there might be other ways to do this that work well.

@cbeckr
Copy link

cbeckr commented Aug 5, 2018

Same issue here and I second @avit. Seems this happens because browserify has no anchor point to resolve relative paths, since input is piped via stdin.

To reproduce, simply take the command logged by browserify-rails:

cat "/my/project/app/assets/javascripts/admin.js" | \
  /my/project/node_modules/.bin/browserify -t [ babelify --presets [ es2015 ] \
  --extensions .es6.js ] -o "/my/project/tmp/cache/browserify-rails/output20180806-8585-nezezb" -
Error: Cannot find module '../es6/widgets/some_widget.js' from '/my/project'
    at /my/project/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
    at load (/my/project/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
    at onex (/my/project/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
    at /my/project/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
    at FSReqWrap.oncomplete (fs.js:158:21)

However, this would work:

/my/project/node_modules/.bin/browserify -t [ babelify --presets [ es2015 ] \
  --extensions .es6.js ] /my/project/app/assets/javascripts/admin.js

Setting config.browserify_rails.use_browserifyinc = true and clearing the sprockets cache (bundle exec rake assets:clobber) resolves the issue.

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

5 participants