Comments (9)
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
from browserify-rails.
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.
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.
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.
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.
@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:
from browserify-rails.
@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.
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.
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)
- Problem with transpilation of Javascript inside an Engine HOT 2
- EPERM with browserify on Windows, succeeds with browserify-incremental HOT 1
- Wrong lookup path HOT 6
- Require throwing error in rails HOT 1
- Browserify copies modules multiple times HOT 2
- Browserify not doing anything when precompiling assets HOT 1
- What's the advantage of using this gem over rails' new webpacker gem? HOT 5
- Browserify breaks action cable HOT 3
- Production env. randomly not compiling certain .js files HOT 2
- Babel Documentation
- Error requiring .coffee files from a node_module HOT 2
- Encoding::UndefinedConversionError occurs when js file contains Chinese characters HOT 2
- Accessing code outside browserified code HOT 4
- Browserify Rails is skipping a file.
- Browserify-rails is not passing process.env.NODE_ENV to the assets? HOT 1
- Problem when try require module in my html.erb file into script tags HOT 4
- ES6 code with no imports HOT 7
- Rails 5.2 support HOT 6
- Seems to re-browserify everything after restarting dev server HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from browserify-rails.