2

I'm working with React and Browserify and trying to require some components, but i get the error:

Error: Cannot find module './components/pages/Home' from '/.../.../reactCoffee/app/scripts'

File in question is index.cjsx (using coffeescript):

React = require 'react'
Router = require 'react-router'
Routes = Router.Routes
Route = Router.Route
DefaultRoute = Router.DefaultRoute

Home = require './components/pages/Home'
About = require './components/pages/About'

React.render((
  <Router>
    <Route name='home' path='/' handler={Home}>
      <Route name='about' path='about' handler={About} />
    </Route>
  </Router>
), document.querySelector '#spa')

and the file I'm trying to require is:

React = require 'react'
Header = require 'components/Header'
Footer = require 'components/Footer'
Store = require 'Store'
Actions = require 'Actions'

Home = React.createClass

  ...

  render: ->
    return
      <div>
        <Header />
          <h1> HI from React and CJSX </h1>
        <Footer />
      </div>

module.exports = Home

File Structure:

.
├── gulpfile.js
├── package.json
└── app
    ├── styles
    ├── index.html
    └── scripts
        └── index.cjsx
        └── components
            └── Header.cjsx
            └── Footer.cjsx
            └── pages
                └── Home.cjsx
                └── About.cjsx
1
  • Somewhere you are trying to require './components/pages/Home' but the path is incorrect considering the file you are requiring from. Commented Jul 23, 2015 at 6:46

1 Answer 1

1

specify the file's extension since it is not one that Browserify knows

Home = require './components/pages/Home.cjsx'

Or you can add something like this in your package.json to inform Browserify of the additional file extension.

"browserify": {
    "extension": [ "cjsx" ]
}
Sign up to request clarification or add additional context in comments.

1 Comment

This worked, thanks! Now I got past that error but I keep getting 'unexpected indentation' when it parses my .cjsx files. I think it has something to do with me using coffeescript with react

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.