question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lauterrycommented, Mar 28, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found