简体   繁体   中英

React-router error even without using it

I had some problems with react-router-dom, and specifically:

warning.js?8a56:36 Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
    in Router
printWarning @ warning.js?8a56:36
warning @ warning.js?8a56:60
checkReactTypeSpec @ checkReactTypeSpec.js?d08c:80
validatePropTypes @ ReactElementValidator.js?a599:161
createElement @ ReactElementValidator.js?a599:213
(anonymous) @ app.jsx?0ec4:14
(anonymous) @ bundle.js:1289
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:66
(anonymous) @ bundle.js:69
Router.js?a4aa:31 Uncaught TypeError: Cannot read property 'location' of undefined
    at new Router (eval at <anonymous> (bundle.js:794), <anonymous>:39:52)
    at eval (eval at <anonymous> (bundle.js:2335), <anonymous>:295:18)
    at measureLifeCyclePerf (eval at <anonymous> (bundle.js:2335), <anonymous>:75:12)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (eval at <anonymous> (bundle.js:2335), <anonymous>:294:16)
    at ReactCompositeComponentWrapper._constructComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:280:21)
    at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:188:21)
    at Object.mountComponent (eval at <anonymous> (bundle.js:387), <anonymous>:46:35)
    at ReactCompositeComponentWrapper.performInitialMount (eval at <anonymous> (bundle.js:2335), <anonymous>:371:34)
    at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:258:21)
    at Object.mountComponent (eval at <anonymous> (bundle.js:387), <anonymous>:46:35)

I was wondering where that may be coming from. I removed it completely from the compiled file.

I use webpack to compile the main react file, which I modified to be as simple as possible just to find out where that annoying error is coming from:

app.js

import ReactDom from 'react-dom';
const Error = () => <h1>Error</h1>;


ReactDom.render(
    <Error/>
    ,
    document.getElementById('react-app'));

So I basically don't use react-router-dom anywhere anymore, but for some reason the errors stay there.

The webpack coniguration:

module.exports = {
    entry: './client/src/app.js',
    devtool: '#eval-source-map',
    output: {
        path: __dirname + '/client/dist/',
        filename: 'bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /(node_modules|app-server.js)/,
                loader: 'babel-loader'
            }
        ]
    }
};

I suggest you:

  1. Delete build *.js files.
  2. Check Is not react-router-dom in the package.json file.
  3. If yes then npm uninstall --save react-router-dom in other case remove node_modules directory, install packages again, and check build.

You can also try build your code for test with browserify:

npm install -g browserify
browserify ./client/src/app.js -o ./client/dist/bundle.js -t [ babelify --presets [ es2015 react ] ] -v

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM