In this post, we will see How To Fix - "Uncaught Error: Invariant Violation: Element Type is Invalid:". Various formats of the above error -
Uncaught Error: Invariant Violation: Element type is invalid: expected a string
(for built-in components) or a class/function (for composite components) but got: object.
Invariant Violation: Element type is invalid expected a string
(for built-in components) or a class/function (for composite components) but got: undefined
import x from './X' <--- Throws Error
import x from './X' **;** <--- No Error
export default A(); <--- Throws Error
export default A; <--- No Error
export default class <THE\_NAME>
In that case, do not use {} when you import. See below example -
import { component } from "react" <--- Throws Error
import component from "react" <--- No Error
Or scenario
import {SOMETHING} from '../SOMEJS.js' <--- Throws Error
import SOMETHING from '../SOMEJS.js' <--- No Error
But if you don't have the "default" in your export - like shown below, then you have to use the {} i.e. you should import it as a named export.
export class classA
import {a} from classA
<Tag>
/\*{ oldComponent }\*/ <--- Throws Error
</Tag>
<Tag>
**{**/\*{ oldComponent }\*/**}** <--- No Error
</Tag>
"react-router-dom": "^x.y.z"
var X = require('./components/Home').default
import { Link } from 'react-router' <--- Throws Error
import SOMETHING from 'react-router-dom' <--- No Error
npm install react-router-redux@next
"react-router-redux": "<^NEW\_VERSION>"
Hope this helps to solve the issue.
element type is invalid: expected a string but got: object ,element type is invalid: expected a string but got: undefined ,element type is invalid: expected a string jest ,element type is invalid: expected a string (for built-in components) or a class/function ,element type is invalid: expected a string react table ,element type is invalid: expected a string react-native ,uncaught invariant violation: spec.type must be defined ,did you accidentally export a jsx literal instead of a component? ,Invariant Violation: Element Type is Invalid ,invariant violation element type is invalid ,invariant violation element type is invalid react native ,invariant violation element type is invalid check the render method ,enzyme mount invariant violation element type is invalid ,invariant violation element type is invalid expected a string ,invariant violation element type is invalid expected a string but got object ,invariant violation element type is invalid expected a string (for built-in components) or ac ,element type is invalid in react native ,element type is invalid expected a string ,invariant violation element type is invalid expected a string (for built-in components) ,jest invariant violation element type is invalid expected a string ,uncaught invariant violation element type is invalid expected a string ,element type is invalid check the render method ,react invariant violation element type is invalid ,uncaught invariant violation element type is invalid ,element type is invalid expected a string react-native ,react native invariant violation element type is invalid expected a string ,invariant violation react native , , , ,enzyme mount invariant violation element type is invalid ,invariant violation element type is invalid ,invariant violation element type is invalid check the render method ,invariant violation element type is invalid dart ,invariant violation element type is invalid detected ,invariant violation element type is invalid django ,invariant violation element type is invalid expected a string ,invariant violation element type is invalid expected a string (for built-in components) ,invariant violation element type is invalid expected a string (for built-in components) or ac ,invariant violation element type is invalid expected a string but got object ,invariant violation element type is invalid hp ,invariant violation element type is invalid hpe ,invariant violation element type is invalid hplc ,invariant violation element type is invalid kafka ,invariant violation element type is invalid keras ,invariant violation element type is invalid kotlin ,invariant violation element type is invalid laravel ,invariant violation element type is invalid leetcode ,invariant violation element type is invalid length ,invariant violation element type is invalid literal ,invariant violation element type is invalid parameter ,invariant violation element type is invalid php ,invariant violation element type is invalid powershell ,invariant violation element type is invalid python ,invariant violation element type is invalid pytorch ,invariant violation element type is invalid query ,invariant violation element type is invalid queue ,invariant violation element type is invalid quora ,invariant violation element type is invalid quotes ,invariant violation element type is invalid react native ,invariant violation element type is invalid value ,invariant violation element type is invalid vba ,invariant violation element type is invalid vector ,invariant violation element type is invalid why ,invariant violation element type is invalid windows ,invariant violation element type is invalid xml ,invariant violation element type is invalid xor ,invariant violation element type is invalid xpath ,invariant violation element type is invalid yaml ,invariant violation element type is invalid yarn ,invariant violation element type is invalid yes or no ,invariant violation element type is invalid yet ,invariant violation element type is invalid yield ,invariant violation element type is invalid youtube ,invariant violation element type is invalid zendesk ,invariant violation element type is invalid zerodha ,invariant violation element type is invalid zip ,invariant violation element type is invalid zoho ,invariant violation element type is invalid zoom ,jest invariant violation element type is invalid expected a string ,react invariant violation element type is invalid ,react native invariant violation element type is invalid ,uncaught invariant violation element type is invalid ,uncaught invariant violation element type is invalid expected a string