Skip to content
This repository was archived by the owner on May 22, 2024. It is now read-only.

top-level await not possible #1178

@acarl005

Description

@acarl005

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions