Skip to content
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

Ignore unsupported Top-level await and pass it anyway #2742

Closed
theseyan opened this issue Dec 13, 2022 · 2 comments
Closed

Ignore unsupported Top-level await and pass it anyway #2742

theseyan opened this issue Dec 13, 2022 · 2 comments

Comments

@theseyan
Copy link

I'm bundling with format CJS for Bun, which supports both esm and cjs Top level await in the same file.
But due to esbuild having a non-configurable error on using TLAs when format cjs is enabled, it's not currently possible to make use of Bun's TLA features.

I request the addition of a configuration option such as ignoreUnsupportedTLA which will allow users to manually pass through TLAs that would normally be blocked with cjs.

@evanw
Copy link
Owner

evanw commented Dec 13, 2022

I'm not at all familiar with Bun. But I did try using top-level await in a CommonJS file and it doesn't appear to be supported? Here's what I tried:

  • entry.js:

    console.log(require('./cjs-tla.js'))
  • cjs-tla.js:

    await new Promise(r => setTimeout(r, 1000))
    module.exports = 123

When running this with bun run entry.js I get this error:

1 | __require as require
2 | } from "bun:wrap";
3 | 
4 | console.log(import.meta.require("./cjs-tla.js"));
                       ^
TypeError: require() async module "./cjs-tla.js" is unsupported
      at ./entry.js:1:20

This is not surprising because the CommonJS module format doesn't support top-level await.

@theseyan
Copy link
Author

I seem to be able to reproduce this too, but I could've sworn I saw Bun do this in a previous version.
Anyway, I should've tested it first, thank you for taking a look!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants