此错误的含义。我安装了react-router,react-dom,react-scripts all latest。
下面是代码
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
var ReactRouter = require('react-router');
var UserInfo = require('./Components/UserInfo');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var routes = (
<Router history={ReactRouter.browserHistory}>
<Route path="/" component={App}>
<Route path="user/:username" component={UserInfo} />
</Route>
</Router> );
App.js文件看起来像
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
var history = require('react-router').browserHistory;
class App extends Component {
submitUser(event)
{
event.preventDefault();
history.push('/user/${this.refs.inputUser.value}');
}
}
编译失败。
./ node_modules /反应路由器/ ES / Redirect.js 找不到模块:无法解决'D:\ PROJECTS \ react-search \ node_modules \ react-router \ es'中的'react'
答案 0 :(得分:0)
您说您安装了react-dom
等,但是您安装了react
?
您的应用有package.json
个文件吗?如果是这样,它是否在依赖项列表中包含react
?如果是,您是否尝试过npm install
?如果安装正确,您的react
目录中应该有一个名为node_modules
的目录。