Skip to content

Commit

Permalink
fix(netlify): bundle netlify functions as ESM to support top-level aw…
Browse files Browse the repository at this point in the history
…ait (#8661)
  • Loading branch information
Skn0tt authored Sep 25, 2023
1 parent 954cadc commit 008f764
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/witty-carrots-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/netlify': patch
---

fix build failures because of CJS builds and top-level await
12 changes: 11 additions & 1 deletion packages/integrations/netlify/src/integration-functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { AstroAdapter, AstroConfig, AstroIntegration, RouteData } from 'astro';
import { extname } from 'node:path';
import { extname, join } from 'node:path';
import { writeFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { generateEdgeMiddleware } from './middleware.js';
import type { Args } from './netlify-functions.js';
Expand Down Expand Up @@ -85,6 +86,15 @@ function netlifyFunctions({
}
},
'astro:build:done': async ({ routes, dir }) => {
const functionsConfig = {
version: 1,
config: {
nodeModuleFormat: "esm"
}
}
const functionsConfigPath = join(fileURLToPath(_config.build.server), "entry.json")
await writeFile(functionsConfigPath, JSON.stringify(functionsConfig))

const type = builders ? 'builders' : 'functions';
const kind = type ?? 'functions';

Expand Down

0 comments on commit 008f764

Please sign in to comment.