-
Notifications
You must be signed in to change notification settings - Fork 26.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic import fails on named exports #2940
Comments
The problem seems to be at https://github.com/zeit/next.js/blob/master/server/build/babel/plugins/handle-import.js#L17, where An ugly workaround to this problem: const DynamicFoo = dynamic(import('../components/Foo').then(m => {
const {Foo} = m;
Foo.__webpackChunkName = m.__webpackChunkName;
return Foo;
})); Could a better solution be to set |
Also, FWIW, the semantics of
P.S.: Less important but as a bonus, |
Another idea: maybe Anyway, I'd be motivated to investigate more and help out with this, but only if there's interest on your part. |
@herrstucki @timneutkens Was this issue solved in some way? I'm on |
@ichyr it's not resolved yet. You need to still do this: #2940 (comment) We did all these changes to allow seamless SSR for dynamic imports. |
Errors in dynamic imports are silenced which could confound this issue. See #3897. |
Expected Behavior
Dynamically importing a named export should work like this:
Additionally, default exports need also to be explicitly imported when following the spec – something that TypeScript needs you to do, otherwise you'll get an error.
Current Behavior
When accessing a page with an import like above, I get the following error:
(oddly, this doesn't happen when the named import is added to a hot-reloaded page)
Context
m.__webpackChunkName
looks suspicious because the chunk name turns out to beundefined
triggering above error, e.g. https://github.com/zeit/next.js/blob/master/lib/dynamic.js#L69The text was updated successfully, but these errors were encountered: