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.

Handling failed dynamic imports

See original GitHub issue

Feature request

Is your feature request related to a problem? Please describe.

Example: A website with lazy loading components. While scrolling down, your mobile internet might be cut off. Once you get to the bottom, parts of the website won’t be displayed because fetching the chunks failed. Those components will remain stuck in their loading state, even when internet connectivity is back.

Describe the solution you’d like

In our case we would like to catch the error and maybe display an error message and also a button that lets users try again on fetching the chunks.

const DynamicComponent = dynamic(
  () => import("../../components/DynamicComponent"),
  { 
    loading: () => <span>loading...</span>,
    errorMsg: () => <span>Network interruption detected</span>,
    retry: () => <button>Try again</button>,
  },
);

Additional context

2020-02-11_18-01

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
Janpotcommented, Feb 11, 2020

Wouldn’t this work?

const DynamicComponent = dynamic(() => {
  return import("../../components/DynamicComponent")
    .catch(() => <span>Network interruption detected</span>)
});
0reactions
balazsorban44commented, Jan 29, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling failed dynamic imports · Issue #10495 · vercel/next.js
Example: A website with lazy loading components. While scrolling down, your mobile internet might be cut off. Once you get to the bottom,...
Read more >
What is the best practice for dealing with a failed dynamic ...
I use Webpack dynamic imports to split my bundle. In particular, I often use it with React.lazy like so const Component = React.lazy(() ......
Read more >
How to Handle Dynamic Import Errors in Vuejs
Today, I'm going to talk about dynamic import error handling. ... In Vuejs, we can set import methods return value to component key...
Read more >
Dynamic Import, Code Splitting, Lazy Loading, and Error ...
You will encounter the error: “Cannot find module with dynamic import.” This error comes from Webpack, which is used by Create React App....
Read more >
Confusing error message when using dynamic import with ...
If I run import("./foo.js") where foo.js does not exist I already get a good error: TypeError: error loading dynamically imported module.
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