reactjs – React.createElement: type is invalid — expected a string
reactjs – React.createElement: type is invalid — expected a string
Most of the time this is due to an incorrect export/import.
Common error:
// File: LeComponent.js
export class LeComponent extends React.Component { ... }
// File: App.js
import LeComponent from ./LeComponent;
Possible option:
// File: LeComponent.js
export default class LeComponent extends React.Component { ... }
// File: App.js
import LeComponent from ./LeComponent;
There are a few ways it could be wrong, but that error is because of an import/export mismatch 60% of the time, everytime.
Edit
Typically you should get a stacktrace that indicates an approximate location of where the failure occurs. This generally follows straight after the message you have in your original question.
If it doesnt show, it might be worth investigating why (it might be a build setting that youre missing). Regardless, if it doesnt show, the only course of action is narrowing down where the export/import is failing.
Sadly, the only way to do it, without a stacktrace is to manually remove each module/submodule until you dont get the error anymore, then work your way back up the stack.
Edit 2
Via comments, it was indeed an import issue, specifically importing a module that didnt exist
I was getting this error as well.
I was using:
import BrowserRouter from react-router-dom;
Fix was doing this, instead:
import { BrowserRouter } from react-router-dom;
reactjs – React.createElement: type is invalid — expected a string
Try this
npm i [email protected]
in your App.js
import { BrowserRouter as Router, Route } from react-router-dom
const Home = () => <h1>Home</h1>
const App = () =>(
<Router>
<Route path=/ component={Home} />
</Router>
)
export default App;