-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
loadable.lib
Webpack 5 dynamic import/chunk name bug
#750
Comments
Hey @wvanrensselaer 👋, |
Actually impacts regular loadable components too: https://github.com/wvanrensselaer/loadable-components-bug/compare/test-regular-loadable |
Actually a very interesting problem. So "sometimes" webpack 5 does not obey the chunk name it was given. The simplest and most error-resilient way would be to stop relaying on chunk names/generating chunk names, and do a reverse search from the stats for the given file name - there is a piece of extra information on how files are connected to chunks as well as how chunks are connected to each other... and it was just removed - #735 The issue requires a little more investigation before moving forward, as it might cause a major architecture change. |
Related: #740 |
That could be good. Might be tricky too though since Webpack does its best to hide the generated filenames, only accessible by calling |
Both The problem is right now There are at least two ways to do it::
|
Had some time to dig into this some more. I think we can patch the Babel plugin as a quick fix, need to rework const Translations = loadable.lib((props) => import(`./translations.${props.locale}.json`)); Transforms to: const Translations = loadable.lib({
chunkName(props) {
return `translations-${props.locale}-json`.replace(/[^a-zA-Z0-9_!§$()=\-^°]+/g, "-");
},
importAsync: props => import(
- /* webpackChunkName: "translations-[request]" */
+ /* webpackChunkName: "[request]" */
`./translations/messages.${props.locale}.json`
)
}); I'll try to put a PR together this week. Can work around this for now by using the full file name in the template literal expression: const Translations = loadable.lib((props) => import(`./${props.file}.json`));
<Translations file={`translations.${locale}`}> |
Not sure this is the right way to move forward. We can or 100% control chunk names, or 100% not. Something in between is not an option, and will for example, not work for wp4, or some future wp5 version, as in this very internal-ish moment. |
This would still be 100% control of chunk names, just fixing the bug with |
So the problem also actual for wp4 and the fix is valid for wp4 as well? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
🐛 Bug Report
Using a dynamic import with
loadable.lib
and Webpack 5 leads toChunkExtractor
error in SSR. Can reproduce in this repo.Relevant code in
Application.js
:Chunk names in
loadable-stats.json
come out as:Error during SSR is:
Trying to get
translations-en-US-json
, but the chunk name istranslations-translations-en-US-json
. I think it's an issue generating the chunk name in the Babel plugin here but not quite sure how best to fix yet. Compiled code in the bundle comes out to:But that should be
translations-translations-${props.locale}-json
in this case.To Reproduce
Clone the demo repo here and follow instructions in README to run the code.
Expected behavior
Resolves the correct chunk name in SSR.
Link to repl or repo (highly encouraged)
https://github.com/wvanrensselaer/loadable-components-bug
Run
npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard
Paste the results here:
The text was updated successfully, but these errors were encountered: