Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React TypeError: __WEBPACK_IMPORTED_MODULE_0_react__.PropTypes is undefined

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:

error screenshot

like image 215
hkjhadj1 Avatar asked Apr 04 '18 15:04

hkjhadj1


2 Answers

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"
like image 182
Ericcur Avatar answered Sep 23 '22 08:09

Ericcur


import PropTypes from 'prop-types';

React.PropTypes has moved into a different package since React v15.5. Please use the prop-types library instead.

like image 23
Mai Avatar answered Sep 24 '22 08:09

Mai