browserify cannot find module 'react'

James Lin picture James Lin · May 5, 2015 · Viewed 11.9k times · Source

I have this bit of react code called main.js:

var React = require('react');

var Comment = React.createClass({
render: function(){
  return (
    <div className="comment">
      <h2 className="commentAuthor">
        {this.props.author}
      </h2>
      <span dangerouslySetInnerHTML={{__html:marked(this.props.children.toString(), {sanitize:true})}} />
    </div>
  );
}
});

And I am trying to use browserify and reactify with it:

browserify -t reactify main.js

But I am getting this error:

Error: Cannot find module 'react' from '/Users/jameslin/projects/reactjs/react-0.13.2'
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:46:17
    at process (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:173:43)
    at ondir (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:188:17)
    at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:69:43)
    at onex (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:92:31)
    at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:22:47
    at Object.oncomplete (fs.js:107:15)

Given that I have installed react and reactify npm modules by:

  • npm install -g react
  • npm install -g reactify

Answer

James Lin picture James Lin · May 5, 2015

The moment I posted my question, and seems I found the answer, installed the module locally fixed it.

npm install react

But then I get another error:

Error: EMFILE, open '/Users/jameslin/node_modules/react/package.json'

UPDATE:

running ulimit -n 10000 fixed the issue