React-Router cannot read undefined property string

I am new to React and I am building my first application with React, Redux and React Router, so far I have successfully set up my boiler plate, however, when I want to use React-Router and create routes, I get the following error

TypeError: Cannot read property 'string' of undefined ./node_modules/react-router-dom/es/BrowserRouter.js node_modules/react-router-dom/es/BrowserRouter.js:38 35 | }(React.Component); 36 | 37 | BrowserRouter.propTypes = { > 38 | basename: PropTypes.string, 39 | forceRefresh: PropTypes.bool, 40 | getUserConfirmation: PropTypes.func, 41 | keyLength: PropTypes.number, 

This happens when I try to import and use

 import { BrowserRouter, Route } from 'react-router-dom'; 

Here is my index.js

 import React, { Component } from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; import store from './store' import { BrowserRouter, Route } from 'react-router-dom'; import './index.css'; import App from './App'; import registerServiceWorker from './registerServiceWorker'; class Hello extends Component { render(){ return( <div>Hello</div> ) } } class GoodBye extends Component { render(){ return( <div>GoodBye</div> ) } } ReactDOM.render(<Provider store={store}> <BrowserRouter> <Route path="/hello" component={Hello}/> <Route path="/goodbye" component={GoodBye}/> </BrowserRouter> </Provider>, document.getElementById('root')); registerServiceWorker(); 

And my .json package

 { "name": "reactreduxrouterblog", "version": "0.1.0", "private": true, "dependencies": { "axios": "^0.16.2", "react": "^16.0.0", "react-dom": "^16.0.0", "react-redux": "^5.0.6", "react-router": "^2.0.0-rc5", "react-router-dom": "^4.0.0", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-promise-middleware": "^4.4.1", "redux-thunk": "^2.2.0" }, "devDependencies": { "react-scripts": "1.0.14" }, "scripts": { "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test --env=jsdom", "eject": "react-scripts eject" } } 

Any knowledge would be appreciated!

+5
source share
2 answers

Try adding PropTypes to your application.

 basename: PropTypes.string 

It looks like you are just missing this package.

EDIT:

Be sure to run npm install to install all the dependencies.

+2
source
 import React from 'react'; <--as normal import PropTypes from 'prop-types'; <--add this as a second line App.propTypes = { monkey: PropTypes.string, <--omit "React." cat: PropTypes.number.isRequired <--omit "React." }; //Wrong: React.PropTypes.string //Right: PropTypes.string 
+1
source

Source: https://habr.com/ru/post/1272537/


All Articles