Switch causing "Element type is invalid" in Vite production build
See original GitHub issueThe Switch
component causes a React error in the production build of a Vite project. It does not error in development mode. When you build and view a production build, you get a link to the following React error:
https://reactjs.org/docs/error-decoder.html/?invariant=130&args[]=object&args[]=
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
OS: Windows 10, but probably all Browser: Chrome, Firefox, Edge Reproduction: https://stackblitz.com/edit/vitejs-vite-zsmuma?file=src/App.tsx
Reproduction steps:
- Use the
Switch
component in a Vite project - Build the project (
npm run build
) - Preview/serve the project (
npm run preview
, browser to http://localhost:5000)
I’m not sure if this is an issue with this project or with Vite, but thought I would start here as I’ve used Vite a bunch and never ran into this error before attempting to use this Switch component. Thank you for your work!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:9 (6 by maintainers)
Top Results From Across the Web
reactjs - Element type is invalid: expected a string (for built-in ...
1. Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >(React) Element type is invalid, expected a string (for built in ...
The error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got" occurs for...
Read more >Troubleshooting common React Native bugs - LogRocket Blog
Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but ...
Read more >element type is invalid. received a promise that resolves to
I have the following error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: ......
Read more >react × Error: Element type is invalid: expected a string (for built-in ...
The second one works while the first is causing the error. Or the opposite.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ESM support was shipped in 7.0.0. I checked that it works with Vite when using the normal import syntax and it does.
ESM support was shipped in 7.0.0. I checked that it works with Vite when using the normal import syntax and it does.