Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Webpack babel es6 giving me errors with react-router 1.0 "module not found"?

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

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']
                }

            }
        ]
    }
}

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",

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!

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!

like image 568
Rolando Avatar asked Nov 29 '15 03:11

Rolando


1 Answers

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

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+.

Run npm install history and you should be good.

like image 147
enjoylife Avatar answered Oct 19 '22 16:10

enjoylife