首先,我是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