From aaedb848b1d6f683840035865528506a346ea659 Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Wed, 31 Jan 2024 13:51:56 -0600 Subject: [PATCH] Silently ignore adapters that don't export `start()` (#9911) --- .changeset/tiny-moose-melt.md | 5 +++++ packages/astro/src/core/build/plugins/plugin-ssr.ts | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changeset/tiny-moose-melt.md diff --git a/.changeset/tiny-moose-melt.md b/.changeset/tiny-moose-melt.md new file mode 100644 index 0000000000..aba946fe70 --- /dev/null +++ b/.changeset/tiny-moose-melt.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes an issue where some adapters that do not include a `start()` export would error rather than silently proceed diff --git a/packages/astro/src/core/build/plugins/plugin-ssr.ts b/packages/astro/src/core/build/plugins/plugin-ssr.ts index 79bfd1ece4..df48374fdb 100644 --- a/packages/astro/src/core/build/plugins/plugin-ssr.ts +++ b/packages/astro/src/core/build/plugins/plugin-ssr.ts @@ -263,7 +263,14 @@ function generateSSRCode(adapter: AstroAdapter, middlewareId: string) { return `export const ${name} = _exports['${name}'];`; } }) ?? []), - `serverEntrypointModule.start?.(_manifest, _args);`, + // NOTE: This is intentionally obfuscated! + // Do NOT simplify this to something like `serverEntrypointModule.start?.(_manifest, _args)` + // They are NOT equivalent! Some bundlers will throw if `start` is not exported, but we + // only want to silently ignore it... hence the dynamic, obfuscated weirdness. + `const _start = 'start'; +if (_start in serverEntrypointModule) { + serverEntrypointModule[_start](_manifest, _args); +}`, ]; return {