-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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(netlify): bundle netlify functions as ESM to support top-level await #8661
Conversation
🦋 Changeset detectedLatest commit: 76e5cb1 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
const functionsConfigPath = join(fileURLToPath(_config.build.server), "entry.json") | ||
await writeFile(functionsConfigPath, JSON.stringify(functionsConfig)) | ||
|
||
// await writeFile(_config.build.server) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to remove! Not sure what happened there, should get some coffee :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done in 76e5cb1
version: 1, | ||
config: { | ||
nodeModuleFormat: "esm" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this documented somewhere? 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, sadly not! It's more of a stop-gap solution until we start outputting to ESM for all functions - but there's always sites that break in that migration, so we're pretty careful about it. There's something in the works on this though, i'm hoping we can remove this again in a couple months! Will let you know about it then :)
Thanks for the quick turnaround! |
Changes
#8598 included a change that makes Astro emit functions with top-level await, specifically this line:
astro/packages/astro/src/vite-plugin-markdown/index.ts
Line 146 in 863f517
Top-Level await is supported in ESM, but not in CJS. By default, Netlify bundles
.mjs
files into CJS files under the hood, so this will result in build failures. To work around that, this PR adds a config file that tells Netlify to bundle into ESM.Testing
I've tested this out on https://github.com/Hiroki1112/hiroki-dev, which is the site I first noticed this bug with. My change fixed their build process.
Docs
It's a fix, so no docs needed.