首先,我是React with Rails的初学者并尝试了一些事情。我目前正在使用路由,并且我不确定哪里出错。请指导我。未被捕获的错误:找不到模块“反应”
我有一个UserWorld.jsx文件的容器文件夹。其内容如下:
import React, { PropTypes } from 'react';
import User from '../containers/User';
// Simple example of a React "smart" component
export default class UserWorld extends React.Component {
constructor(props, context) {
super(props, context);
// How to set initial state in ES6 class syntax
// https://facebook.github.io/react/docs/reusable-components.html#es6-classes
this.state = { users: this.props.data
};
}
render() {
var userNodes = this.state.users.map(function(user) {
return (
<User key={user.id} first_name={user.first_name} last_name={user.last_name} email={user.email} city={user.city} address={user.address} />
);
});
return (
<table>
<thead>
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Address</td>
<td>City</td>
</tr>
</thead>
<tbody>
{userNodes}
</tbody>
</table>
);
}
}
现在,我想添加一个链接,我包括
import { Router, Route, Link, browserHistory, IndexRoute } from 'react-router'
但是这给了我一个错误在控制台,如下所示:
Uncaught Error: Cannot find module "react"
Exception in rendering!
message: Could not find component registered with name UserWorldApp. Registered component names include [ HelloWorldApp ]. Maybe you forgot to register the component?
现在我不知道这里发生了什么。如果有人能帮助我在这里,我将不胜感激。另外,如果我可以得到相同的参考。我遇到了各种各样的语法问题。
更新:
我看到错误出现在var _react = require('react');
线在Router.js在反应路由器文件夹中的文件夹node_modules。
我得到这个控制台:
ERROR in ../~/react-router/lib/Router.js
18:03:09 client.1 | Module not found: Error: Cannot resolve module 'imports' in /Users/c193/Documents/React/test-react-on-rails/node_modules/react-router/lib
18:03:09 client.1 | @ ../~/react-router/lib/Router.js 19:13-29
P.S:所有的文档和文章我读实在是太技术,我听不懂,我只了解位和它的一部分。刚开始我的两周时间。
你安装'react'?你有'package.json'文件吗? – JMM
是的,我有'包。json'文件和我安装了反应和反应路由器使用'npm我反应react-dom react-router -save'和webpack使用'npm我webpack webpack-dev-server babel-core babel-loader babel-preset-es2015 babel -preset-react --save-dev' – Aakanksha
很难说出发生了什么,因为你有太多的错误消息。例如,您发布了此错误消息:'错误:无法解析模块'imports''。目前还不清楚这与'无法找到模块'反应''错误有什么关系。 React和React Router在同一个'node_modules /'中,对吗? – JMM