Webpack babel es6给我的错误与反应路由器1.0“模块未找到”? [英] Webpack babel es6 giving me errors with react-router 1.0 "module not found"?

查看:147
本文介绍了Webpack babel es6给我的错误与反应路由器1.0“模块未找到”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我反应路由器出现以下错误,其引用的错误看起来像是在我的应用程序代码之外,但是与反应路由器库本身有关:

I am getting the following errors with react-router, the errors its referring to looks like it is outside my application code, but with the react-router library itself:

ERROR in ./~/react-router/lib/Router.js
Module not found: Error: Cannot resolve module 'history/lib/createHashHistory' in /Users/kmartinez/apache/www/reactroutesample/node_modules/react-router/lib
 @ ./~/react-router/lib/Router.js 25:35-75

ERROR in ./~/react-router/lib/useRoutes.js
Module not found: Error: Cannot resolve module 'history/lib/Actions' in /Users/kmartinez/apache/www/reactroutesample/node_modules/react-router/lib
 @ ./~/react-router/lib/useRoutes.js 15:25-55

ERROR in ./~/react-router/lib/useRoutes.js
Module not found: Error: Cannot resolve module 'history/lib/useQueries' in /Users/kmartinez/apache/www/reactroutesample/node_modules/react-router/lib
 @ ./~/react-router/lib/useRoutes.js 17:28-61

ERROR in ./~/react-router/lib/match.js
Module not found: Error: Cannot resolve module 'history/lib/createMemoryHistory' in /Users/kmartinez/apache/www/reactroutesample/node_modules/react-router/lib
 @ ./~/react-router/lib/match.js 13:37-79

ERROR in ./~/react-router/lib/match.js
Module not found: Error: Cannot resolve module 'history/lib/useBasename' in /Users/kmartinez/apache/www/reactroutesample/node_modules/react-router/lib
 @ ./~/react-router/lib/match.js 17:29-63

当我使用JSX语法时,一切正常,但是一旦我将babel-es2015-preset添加到我的网络包中,并希望开始切换到ES6 / ES2015,我得到了上面的错误。什么给了?

Everything was working when I was using the "JSX" syntax, but as soon as I added in "babel-es2015-preset" into my webpack and wanted to start switching to ES6/ES2015, I got the errors above. What gives?

module.exports = {
    entry: './app/App.js',
    output: {
        filename: 'public/bundle.js',
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel',
                query: {
                    presets: ['es2015','react']
                }

            }
        ]
    }
}

我正在使用最新版本的反应路由器,反应和babel。 Package.json包含以下内容:

I am using the latest verison of react-router, react, and babel. Package.json contains the following:

    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "react-dom": "^0.14.3",
    "webpack": "^1.12.9",
"react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-router": "^1.0.0",
"babel-preset-react": "^6.1.18",

我的当前代码包含一些文件中的JSX语法,而其他文件中包含ES6 / ES2015导入语法。如果有更好的装载机,或者我配置的webpack错误,请指教!

My current code contains both JSX syntax in some files, and ES6/ES2015 import syntax in others. If there is a better set of loaders or if I misconfigured webpack, please advise!

我的App.js中唯一的一行是:

The only lines I have in my App.js are:

import React from 'react';
import ReactDOM from 'react-dom';
import {Router, Route} from 'react-router';

如果我注释了第三行,那么首先提到的错误就会消失,但是我需要使用反应路由器!

If I comment out that third line, then the errors first mentioned go away, but I need to use react-router!

推荐答案

我假设你使用npm 3+。并且React Router的安装文档状态:

Im assuming your using npm 3+. And React Router's install docs state:


请注意,您还需要安装历史包,因为它是React Router的对等依赖关系,并且赢得在npm 3+中自动为您安装。

Note that you need to also install the history package since it is a peer dependency of React Router and won't automatically be installed for you in npm 3+.

运行 npm安装历史记录你应该很好。

这篇关于Webpack babel es6给我的错误与反应路由器1.0“模块未找到”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆