React Lazy - Element type is invalid. Received a promise that resolves to: [object Promise]. Lazy element type must resolve to a class or function.
See original GitHub issueI am trying to code split with React lazy and get error:
Element type is invalid. Received a promise that resolves to: [object Promise]. Lazy element type must resolve to a class or function.
import React, { lazy, Suspense } from 'react'
import * as ReactDOM from 'react-dom'
const Foo = React.lazy(() => import('./foo/foo'))
const App = () => {
return (
<div>
<Suspense fallback={<div>Loading...</div>}>
<Foo />
</Suspense>
</div>
)
}
repo: https://github.com/jcmoore0/react-lazy-fuse/tree/master/src
Is this method supported? Fusebox V4 is fantastic. Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
javascript - Received a promise that resolves to: undefined ...
Element type is invalid. Received a promise that resolves to: undefined. Promise elements must resolve to a class or function. This is SibaCard ......
Read more >element type is invalid. received a promise that resolves to
Received a promise that resolves to: [object Promise]. Lazy element type must resolve to a class or function. import React, { lazy, Suspense...
Read more >(React) Element type is invalid, expected a string (for built in ...
To solve the error "Element type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got",...
Read more >Lazy Element Type Must Resolve To A Class Or Function (In ...
Received a promise that resolves to: [object Promise]. Lazy element type must resolve to a class or function. import React, { lazy, Suspense...
Read more >lazy - React Docs
You need to return a Promise or some other thenable (a Promise-like object with a then method). It needs to eventually resolve to...
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
According to React documentation route-based-code-splitting:
React.lazy currently only supports default exports. If the module you want to import uses named exports, you can create an intermediate module that reexports it as the default. This ensures that tree shaking keeps working and that you don’t pull in unused components.So you should do the next steps, for not default modules
For me it helps.
@jcmoore0 thanks 😉 I think it clearly states the error.
Received a promise that resolves to: [object Promise]. Lazy element type must resolve to a class or function.or
defaultas you wish. I am closing this issue since it’s obvious. You can also try react-universal example