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.

[question] whats the best way to handle failed imports?

See original GitHub issue

Probably a dumb question but really curious what the best way is to handle if an import like the one below fails. Could be because that remote is down or just a generic error.

If we go with the example below, I’ve noticed that if main is down (for example, I don’t start the dev server), then the GET request that wants to get ExposedLayout just hangs and doesn’t resolve at all.

const Layout = dynamic(
  () => {
    const mod = import('main/ExposedLayout');
    return mod;
  },
  { ssr: false },
);

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ScriptedAlchemycommented, Nov 14, 2022

yeah i usually to import().catch(import(npm))

in future ill introduce delegate modules which will offer more power

0reactions
trent-boydcommented, Nov 2, 2022

I started with an error boundary too, but only had a stack trace rendered to the page. I could prevent that by adding a catch to the import call. The error would be logged to the console for easier debugging, and then I could display some fallback UI.

const RemoteApp = dynamic(
  () =>
    import("remote/app").catch(error => {
      console.error(error);
      return function Fallback() {
        return (
          <span style={{color: "red"}}>
            There was a problem importing your component. Check the console for
            more details.
          </span>
        );
      };
    }),
  {ssr: false}
);

I haven’t tried it, but the fallback component could theoretically be the same fallback component you use in your error boundary.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle import errors - Analytics Help - Google Support
There are several basic reasons why Data Import might not be working for you: Not reporting on the right view. Not using the...
Read more >
What is the best practice for dealing with a failed dynamic ...
Please be sure to answer the question. Provide details and share your research! ... Asking for help, clarification, or responding to other answers ......
Read more >
Review and troubleshoot import errors
Below, learn how to resolve errors detected during an import, download an error file, view error details, and correct issues in your import...
Read more >
Skipping over failed imports until they are needed (if ever)
There is one issue with your approach which is, in the case of multiple import failure, only the last one can be properly...
Read more >
Solutions to common product CSV import problems
Troubleshooting product CSV files. Identify missing fields or headers, illegal formatting or identifier duplications before contacting support.
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