Skip to content

fix: dynamic imports with webpack 5 #294

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

Merged
merged 1 commit into from
May 13, 2021

Conversation

lindsaylevine
Copy link

Fixes #209

why, yes, this IS a tragic hack..

now a serverless function generated for a page (that requires it) will look like:
Screen Shot 2021-05-11 at 4 10 16 PM

previously it was: nextPage/index.js
now it is: nextPage/nextPage/index.js to accommodate looking for chunks two levels up in webpack 5

this is still backwards compatible with webpack 4, but unfortunately with next installed @ ^10.2.0 now in our project, we only test the webpack 5 behavior (< 10.2.0 was still default webpack 4).

i spent a good deal of time exploring the next source and webpack source to see if there was anything we could possibly do upstream to avoid this work. there's really nothing; it's just a breaking change in a major webpack update. everything runs fine on vercel, and i somehow couldn't identify any changes in the next source made to accommodate dynamic imports with webpack 5 - it appears they just work with the same source for wp4 and wp5? not sure.

@github-actions github-actions bot added the type: bug code to address defects in shipped code label May 11, 2021
@lindsaylevine
Copy link
Author

possibly related but very unclear without more info from author: vercel/next.js#24739

Copy link

@lukeocodes lukeocodes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my big concern with this one is that next makes another change upstream and we end up with even more complex logic for imports.

is this something we can help with upstream instead? apologies, read the description properly now.

@lindsaylevine lindsaylevine force-pushed the ll/dynamic-imports-webpack-5 branch from 105b99e to ce4308a Compare May 13, 2021 22:58
Copy link

@jlengstorf jlengstorf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approving this to get a fix out while we explore ways to make this more robust long-term

@lindsaylevine lindsaylevine merged commit ec62ee3 into main May 13, 2021
@lindsaylevine lindsaylevine deleted the ll/dynamic-imports-webpack-5 branch May 13, 2021 23:18
lindsaylevine added a commit that referenced this pull request May 14, 2021
@lindsaylevine lindsaylevine restored the ll/dynamic-imports-webpack-5 branch May 14, 2021 09:33
lindsaylevine added a commit that referenced this pull request May 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug code to address defects in shipped code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Cannot find module on ISR when using dynamic imports
3 participants