GithubHelp home page GithubHelp logo

Comments (9)

alekseyg avatar alekseyg commented on May 26, 2024 1

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)

from browserify-rails.

alekseyg avatar alekseyg commented on May 26, 2024

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

from browserify-rails.

alekseyg avatar alekseyg commented on May 26, 2024

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

from browserify-rails.

cymen avatar cymen commented on May 26, 2024

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.

from browserify-rails.

avit avatar avit commented on May 26, 2024

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.

from browserify-rails.

cymen avatar cymen commented on May 26, 2024

@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

from browserify-rails.

avit avatar avit commented on May 26, 2024

@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?

from browserify-rails.

cymen avatar cymen commented on May 26, 2024

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.

from browserify-rails.

cbeckr avatar cbeckr commented on May 26, 2024

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.

from browserify-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.