Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
See original GitHub issueHi,
i get the following error when i try to use react-select/async.
Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
I just import the async like this
import AsyncSelect from 'react-select/async';
and then i use it as follows: `const Test = () => { const [displaySelect, setDisplaySelect] = useState(false);
useEffect(() => {
setDisplaySelect(true);
}, [])
return (
<div>
{ displaySelect && <AsyncSelect options={[{value: 'ts', label:'test'}]} /> }
</div>
)
}
export default Test;`
I added the setDisplaySelect because we use server side rendering and another error regarding emotion was being displayed. Do you have any ideas what goes wrong?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7
Top Results From Across the Web
Invariant Violation: Element type is invalid: expected a string ...
js:42 Uncaught Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >Element type is invalid: expected a string (for built-in ... - GitHub
createElement: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
Read more >Element type is invalid: expected a string (for built-in ...
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. edit.js :
Read more >Element type is invalid: expected a string (for ... - OneCompiler
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Read more >Element type is invalid: expected a string (for built-in ... - Reddit
Getting Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: ...
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 FreeTop 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
Top GitHub Comments
@ebonow Thank you for the response, I appreciate your help! I did two things yesterday:
Our component library is mostly used to provide consistent styles, so we rarely use 3rd party libs, which I think is why this issue hasn’t arisen before. I modified our Rollup config to export a
umd
bundle instead ofcjs
(along with messing with some other settings), and that actually resolved the issue!For whatever reason, the way we were bundling things wasn’t properly resolving
default
exports from node_modules, I believe. We use one other third party lib and it’s always worked fine, but we do not use the default export in that case.Could it be related to an incorrect import somewhere else in that file? Perhaps this helps: https://stackoverflow.com/a/42814137
The code snippet you included seems to be okay.
Regarding the async select, instead of using
options
, I believe you should be usingdefaultOptions
instead. See example and source code here: https://react-select.com/async#defaultoptions