full dynamic import ssr not working
See original GitHub issue🐛 Bug Report
I encountered the Invariant Violation: loadable: cannot find {chunk-name} in stats
while trying to use full dynamic import with loadable import on server side
To Reproduce
const AsyncText = loadable((props) => import('./brands/${props.brand}/DynamicText'));
and in another file
<AsyncText brand="af" />
Expected behavior
I expected the component at ./brands/af/DynamicText
to render on server side.
Link to repl or repo (highly encouraged)
https://github.com/lauterry/perfect-react-app/tree/full-dynamic-import-ssr
Run BRAND=af npm run build
then BRAND=af npm run start
Run npx envinfo --system --binaries --npmPackages @loadable/component,@loadable/server,@loadable/webpack-plugin,@loadable/babel-plugin --markdown --clipboard
Paste the results here:
## System:
- OS: macOS 10.14.3
- CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
- Memory: 615.75 MB / 16.00 GB
- Shell: 5.3 - /bin/zsh
## Binaries:
- Node: 8.10.0 - /usr/local/bin/node
- Yarn: 1.13.0 - /usr/local/bin/yarn
- npm: 6.4.1 - /usr/local/bin/npm
- Watchman: 4.9.0 - /usr/local/bin/watchman
## npmPackages:
- @loadable/babel-plugin: ^5.7.0 => 5.7.0
- @loadable/component: ^5.7.0 => 5.7.0
- @loadable/server: ^5.7.0 => 5.7.0
- @loadable/webpack-plugin: ^5.7.0 => 5.7.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
full dynamic import ssr not working · Issue #288 - GitHub
I encountered the Invariant Violation: loadable: cannot find {chunk-name} in stats while trying to use full dynamic import with loadable ...
Read more >Next.js dynamic import with server-side-rendering turned off ...
This works fine in development, but when I try to build the project (next build), it throws a "window is not defined" error...
Read more >Advanced Features: Dynamic Import - Next.js
Dynamically import JavaScript modules and React Components and split your code into manageable chunks.
Read more >Dynamic imports and code splitting with Next.js
Unlike static imports, dynamic imports work by applying a method known as code splitting. Code splitting is the division of code into various ......
Read more >Dynamic import() - vite-plugin-ssr
Client-side only components: we can use import() to avoid loading/rendering a component on the server-side. (Some component libraries cannot be server-side ...
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
Ok I found the problem thank to this article https://wanago.io/2018/08/20/webpack-4-course-part-eight-dynamic-imports-with-prefetch-and-preload/
I replace
const AsyncText = loadable((props) => import('./brands/${props.brand}/DynamicText'));
with
const AsyncText = loadable((props) => import('./brands/${props.path}'));
and
<AsyncText brand="af" />
with
<AsyncText brand="af/DynamicText" />
and it works as expected.
Hope it will helps anyone who misunderstand how webpack deals with full dynamic import.
Best
@revskill10 This article should help you 😃
https://engineering.thetrainline.com/optimising-js-bundles-for-internationalisation-378cb28b835e