diff --git a/.changeset/smooth-melons-cough.md b/.changeset/smooth-melons-cough.md new file mode 100644 index 000000000000..0a4a3ea9d84e --- /dev/null +++ b/.changeset/smooth-melons-cough.md @@ -0,0 +1,7 @@ +--- +'@astrojs/vercel': patch +--- + +Prevent race condition with Node 18 + +Using Node 18 there can be a race condition where polyfill for the `crypto` global is not applied in time. This change ensures the polyfills run first. diff --git a/packages/integrations/vercel/src/serverless/entrypoint.ts b/packages/integrations/vercel/src/serverless/entrypoint.ts index 876ab6b07fe3..a881d701ab36 100644 --- a/packages/integrations/vercel/src/serverless/entrypoint.ts +++ b/packages/integrations/vercel/src/serverless/entrypoint.ts @@ -8,14 +8,15 @@ import { ASTRO_PATH_PARAM, } from './adapter.js'; +// Run polyfills immediately so any dependent code can use the globals +applyPolyfills(); + // Won't throw if the virtual module is not available because it's not supported in // the users's astro version or if astro:env is not enabled in the project await import('astro/env/setup') .then((mod) => mod.setGetEnv((key) => process.env[key])) .catch(() => {}); -applyPolyfills(); - export const createExports = ( manifest: SSRManifest, { middlewareSecret, skewProtection }: { middlewareSecret: string; skewProtection: boolean },