Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 'Failed to resolve import' crash during ssr #1496

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mighty-teachers-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

Fix 'Failed to resolve import' crash during ssr
11 changes: 8 additions & 3 deletions packages/start/src/router/lazyRoute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@ 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);
// fallback to an empty component as any errors will surface in the vite overlay
if(!mod) return { default: () => [] };

if (!mod[exported]) console.error(`Module ${component.src} does not export ${exported}`);
const Component = mod[exported];
let assets = await clientManifest.inputs?.[component.src].assets();
const Component = mod[exported]
let assets = await clientManifest.inputs?.[component.src]?.assets();
const styles = assets.filter((asset: Asset) => asset.tag === "style");

if (typeof window !== "undefined" && import.meta.hot) {
Expand Down
2 changes: 1 addition & 1 deletion packages/start/src/server/StartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
// @ts-ignore
const nonce = context.nonce;

let assets: Asset[];
let assets: Asset[] = [];
Promise.resolve().then(async () => {
let assetPromises: Promise<Asset[]>[] = [];
// @ts-ignore
Expand Down