question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch causing "Element type is invalid" in Vite production build

See original GitHub issue

The 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:

  1. Use the Switch component in a Vite project
  2. Build the project (npm run build)
  3. 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
markusenglundcommented, Jun 9, 2022

ESM support was shipped in 7.0.0. I checked that it works with Vite when using the normal import syntax and it does.

0reactions
markusenglundcommented, Jun 9, 2022

ESM support was shipped in 7.0.0. I checked that it works with Vite when using the normal import syntax and it does.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found