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

"Top-level await is not available in the configured target environment" #1096

Closed
o-t-w opened this issue Apr 1, 2021 · 4 comments
Closed

Comments

@o-t-w
Copy link

o-t-w commented Apr 1, 2021

I thought that ESBuild was meant to be able to transpile code so it works in older browsers? Or is the point of target just to show me errors telling me I can't use certain features?

My output format is ES modules, in which I thought top level await is meant to be able to work?

require('esbuild').build({
  entryPoints: ['./src/new-js/international.js', './src/new-js/homepage.js'],
  bundle: true,
  minify: true,
  format: 'esm',
  outdir: 'build/js/new-js',
  target: ['chrome75', 'firefox70', 'safari11'],
}).catch(() => process.exit(1));
@evanw
Copy link
Owner

evanw commented Apr 1, 2021

Some language features can be transpiled but others can't be. Top-level await can't really be transpiled because there's no equivalent older syntax. Up until the introduction of top-level await, all ESM module evaluation was synchronous. There was no way to insert an asynchronous step at the top-level.

@bisubus
Copy link

bisubus commented Apr 1, 2021

@evanw This requires a bundler to be aware of top-level awaits, but I don't see fundamental problems with this. Webpack supports this, doesn't it? I guess an equivalent is that every module export is wrapped with async IIFE.

@evanw
Copy link
Owner

evanw commented Apr 3, 2021

Webpack doesn't even support the ESM output format at all I think (open issue: webpack/webpack#2933) so it's not equivalent. I'm planning to add support for top-level await to the IIFE output format for esbuild, in which case this should work.

@evanw
Copy link
Owner

evanw commented Apr 10, 2021

Closing this as a duplicate of #253, which is the general open issue for top-level await support. I'm using that issue to represent adding top-level await support to the IIFE format.

@evanw evanw closed this as completed Apr 10, 2021
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

3 participants