Browserify:无法从'...'找到模块'...'(Coffeescript + React)

时间:2015-07-23 03:47:28

标签: coffeescript reactjs require browserify

我正在使用React和Browserify并尝试需要一些组件,但我收到了错误:

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

有问题的文件是index.cjsx(使用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')

我想要的文件是:

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

文件结构:

.
├── gulpfile.js
├── package.json
└── app
    ├── styles
    ├── index.html
    └── scripts
        └── index.cjsx
        └── components
            └── Header.cjsx
            └── Footer.cjsx
            └── pages
                └── Home.cjsx
                └── About.cjsx

1 个答案:

答案 0 :(得分:1)

指定文件的扩展名,因为它不是Browserify知道的那个

Collection.update

或者您可以在package.json中添加类似的内容,以通知Browserify其他文件扩展名。

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