I have a codebase that uses top-level await in a JS module. ESBuild seems to be forbidding me from using it due to the “cjs” output format.
Netlify site name: leafy-salamander-acbb48
Failing deploy: Netlify App
Source code: netlify-node16/index.js at master · acarl005/netlify-node16 · GitHub
Error:
1:04:06 PM: ────────────────────────────────────────────────────────────────
1:04:06 PM: 2. Functions bundling
1:04:07 PM: Creating deploy upload records
1:04:06 PM: ────────────────────────────────────────────────────────────────
1:04:06 PM:
1:04:06 PM: Packaging Functions from .netlify/functions-internal directory:
1:04:07 PM: ---------------------------------------------------------------------
** WARNING **
The default Node.js runtime will change to Node v16 on 2022-07-11.
If you need to stay on v14, refer to https://ntl.fyi/pin-js-runtime.
---------------------------------------------------------------------
1:04:06 PM: - render.js
1:04:06 PM:
1:04:06 PM: ✘ [ERROR] Top-level await is currently not supported with the "cjs" output format
1:04:06 PM: .netlify/server/entries/endpoints/index.js:1:13:
1:04:06 PM: 1 │ const name = await Promise.resolve("world");
1:04:06 PM: ╵ ~~~~~
1:04:07 PM:
1:04:07 PM: ❯ Failed to bundle functions with selected bundler (fallback used):
1:04:07 PM: - render.zip
1:04:07 PM:
1:04:07 PM: (Functions bundling completed in 918ms)
A “fallback” function is used after the build fails, and the deploy is considered “successful”. However, the fallback function ends up crashing.