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

Unable to require() code from a gem #29

Open
dustyjewett opened this issue Jul 14, 2014 · 2 comments
Open

Unable to require() code from a gem #29

dustyjewett opened this issue Jul 14, 2014 · 2 comments

Comments

@dustyjewett
Copy link

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.

@martenlienen
Copy link
Collaborator

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.

@stevenmichaelthomas
Copy link

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.

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

3 participants