I am making a react app using routers and I'm getting the following error:
React TypeError: WEBPACK_IMPORTED_MODULE_0_react.PropTypes is undefined
How can I avoid it?
Here the code for the 2 routers, post and profile:
Posts
import React,{Component} from 'react';
class Posts extends Component{
render(){
return <div> Posts </div>
}
}
export default Posts;
Profile
import React,{Component} from 'react';
class Profile extends Component{
render(){
return <div> Profile </div>
}
}
export default Profile;
index.js
import React,{Component} from 'react';
import ReactDOM from 'react-dom';
import {BrowserRouter, Route} from 'react-router-dom';
import PropTypes from 'prop-types';
//COMPONENTS
import Posts from './Components/posts';
import Profile from './Components/profile';
class App extends Component{
render(){
return <div> home </div>
}
}
ReactDOM.render(
<BrowserRouter>
<div>
<Route path="/posts" component={Posts}> </Route>
<Route path="/profile" component={Profile}> </Route>
</div>
</BrowserRouter>
,document.querySelector('#root'))
Here is a screenshot of the error:
I had the same problem and late noticed that I had a typo in my import statement.
Instead of:
import React from "react"
I had:
import {React} from "react"
import PropTypes from 'prop-types';
React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With