gpt4 book ai didi

javascript - React Router 无法解析模块

转载 作者:行者123 更新时间:2023-12-03 13:56:18 26 4
gpt4 key购买 nike

出现此错误...

编辑routes.js以反射(reflect)更改

ERROR in ./app/config/routes.js Module not found: Error: Cannot resolve module 'react-rounter' in /Users/sam/Desktop/battle/app/config @ ./app/config/routes.js 2:19-43

我已经将 webpack 和react-react-dom-react-router-babel等全部安装到我的npm包中。当我运行 npm start 时,出现上述错误。这是我的 package.json/webpack config/router.js 文件

package.json

{
"name": "battle",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"production": "webpack -p",
"start": "webpack-dev-server"
},
"author": "Sam Schaefer <smmschaefer@gmail.com>",
"license": "ISC",
"dependencies": {
"react": "^15.4.0",
"react-dom": "^15.4.0",
"react-router": "^3.0.0"
},
"devDependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.8",
"babel-preset-react": "^6.16.0",
"html-webpack-plugin": "^2.24.1",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
}
}

webpack.config

var HtmlWebpackPlugin = require('html-webpack-plugin')
var HTMLWebpackPluginConfig = new HtmlWebpackPlugin({
template: __dirname + '/app/index.html',
filename: 'index.html',
inject: 'body'
});

module.exports = {
entry: [
'./app/index.js'
],
output: {
path: __dirname + '/dist',
filename: "index_bundle.js"
},
module: {
loaders: [
{test: /\.js$/, exclude: /node_modules/, loader: "babel-loader"}
]
},
plugins: [HTMLWebpackPluginConfig]
};

routes.js

var React = require('react');
var ReactRouter = require('react-router');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var IndexRoute = ReactRouter.IndexRoute;
var Main = require('../components/Main');
var Home = require('../components/Home');

var routes = (
<Router>
<Route path='/' component={Main}>
<Route path='/home' component={Home} />
</Route>
</Router>
);

module.exports = routes;

感谢您的帮助。

最佳答案

问题的错误点:

ERROR in ./app/config/routes.js Module not found: Error: Cannot resolve module 'react-rounter' in /Users/sam/Desktop/battle/app/config @ ./app/config/routes.js 2:19-43

在您的routes.js文件中:

react-rounter
^--- this is probasbly the issue.

那不应该是“react-路由器”吗?更正您的routes.js 文件中的拼写错误,您就可以开始了。

关于javascript - React Router 无法解析模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40730830/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com