browserify-rails
browserify-rails copied to clipboard
Unable to require() code from a gem
I'm attempting to use ReactJS in a project, with browserify. While I can hit http://localhost/assets/react.js and get a file, I get an error when I require('react').
-- Gemfile
gem "browserify-rails", "~> 0.3"
gem 'react-rails', '1.0.0.pre', :git => '[email protected]:reactjs/react-rails.git'
-- Test1.js (breaks with 'module "react" not found')
var react = require('react')
-- Test0.js (works... ish... React is a global, not available from require())
// = require react
I AM able to get browserify to work if I give the full path to the file. OBVIOUSLY this only works in development, on my machine.
-- Test2.js
var react = require('/home/dusty/.rbenv/versions/1.9.3-p392/lib/ruby/gems/1.9.1/gems/react-source-0.10.0/build/react.js');
I'm fairly certain that the config you provide will allow me to load the file, but I'm stumped as to what magic incantation can load files from a gem. I tried to build a shim in my assets directory that //= require react, but while the first file gets processed by sprockets, secondary dependencies don't.
I think, the easiest solution is to install react via npm with npm install --save react
. This will install it into the node_modules
directory, from where you can require it.
Shouldn't we be able to append folders to config.browserify_rails.paths
?
This doesn't seem to work right now, but from the documentation it should?
Trying to solve this same problem.