node.js - 在 npm 中找不到模块

标签 node.js reactjs

如上所述,尝试运行 facebook Flux 应用程序 here 。我有以下 js 应用程序的树结构

│   .bundle.js
│   app.jsx
│   bundle.js
│
├───actions
│       TodoActions.jsx
│
├───components
│       Footer.jsx
│       Header.jsx
│       MainSection.jsx
│       TodoApp.jsx
│       TodoItem.jsx
│       TodoTextInput.jsx
│
├───constants
│       TodoConstants.jsx
│
├───dispatcher
│       AppDispatcher.jsx
│       Dispatcher.jsx
│
└───store
        TodoStore.jsx

在app.jsx中代码就像

 var React = require('react');
var TodoApp = require('./components/TodoApp');

    React.render(
      <TodoApp />,
      document.getElementById('todoapp')
    );

在 TodoApp.jsx 中,我将模块导出为

module.exports = TodoApp;

当我尝试制作 build.js 时,它出现错误,如下所示

Error: Cannot find module './components/TodoApp' from 'c:\www\example\react\flux\js'

不知道我哪里错了?如果我需要提供任何进一步的信息,请告诉我

最佳答案

经过谷歌搜索一段时间后,我得到了解决方案。实际问题是 require 查找 js 扩展名,但我有带有 jsx 的文件。

得到我的解决方案here

关于node.js - 在 npm 中找不到模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28655597/

相关文章:

javascript - HTML/Javascript - 如何将输入字段中的文本显示为 HTML 代码?

javascript - React Router v4 不渲染组件

javascript - Reactjs 追加一个元素而不是替换

reactjs - 将 Material UI 的文本字段从黑色更改为白色

node.js - npm 软件包未安装并出现此错误

javascript - nodejs mysql 无法执行查询

javascript - 如何从 php 脚本给 Node.js 服务器一个命令?

node.js - 为 node.js 模块创建依赖于 docker 的测试是否可以接受?

javascript - 更改数组内对象属性名称的值

javascript - 使用 browserify 和 babel 进行编译 react ,显示 : ReferenceError: React is not defined