Skip to content

Commit

Permalink
catch import errors in lazyRoute in dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Brendonovich committed May 22, 2024
1 parent d38c864 commit fbe3afa
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/start/src/router/lazyRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ export default function lazyRoute<T>(component: any, clientManifest: any, server
if (import.meta.env.DEV) {
let manifest = import.meta.env.SSR ? serverManifest : clientManifest;

const mod = await manifest.inputs[component.src].import();
// import() throws if a module doesn't exist, which includes any
// modules loaded by the route itself, so it's important we catch here
const mod = await manifest.inputs[component.src].import().catch(() => null);
if (!mod) console.error(`Module ${component.src} not found`);
if (!mod[exported]) console.error(`Module ${component.src} does not export ${exported}`);
const Component = mod[exported];
let assets = await clientManifest.inputs?.[component.src].assets();
Expand Down

0 comments on commit fbe3afa

Please sign in to comment.