question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Top-level await is not available in the configured target environment ("es2020")

See original GitHub issue

Describe the bug

When trying to build for netlify, I get the following error:

8:43:48 PM: .svelte-kit/output/server/chunks/db.js:40:11: ERROR: Top-level await is not available in the configured target environment (β€œes2020”)

I’ve set my build target to β€œesnext” in the vite.config.js, as instructed by sveltekit:

import { sveltekit } from '@sveltejs/kit/vite';

/** @type {import('vite').UserConfig} */
const config = {
  build: {
    target: 'esnext'
  },
  plugins: [sveltekit()]
};

export default config;

It would seem as though my target build env is being ignored.

Reproduction

Not sure how to do this, sorry - it’s a private repository. It’s a basic svelte app, however. On Node 18.7.0

Logs

8:43:48 PM: 
8:43:48 PM: > Using @sveltejs/adapter-netlify
8:43:48 PM: ✘ [ERROR] Top-level await is not available in the configured target environment ("es2020")
8:43:48 PM:     .svelte-kit/output/server/chunks/db.js:40:11:
8:43:48 PM:       40 β”‚ const db = await createRxDatabase({
8:43:48 PM:          β•΅            ~~~~~
8:43:48 PM: ✘ [ERROR] Top-level await is not available in the configured target environment ("es2020")
8:43:48 PM:     .svelte-kit/output/server/chunks/db.js:47:0:
8:43:48 PM:       47 β”‚ await db.addCollections({
8:43:48 PM:          β•΅ ~~~~~
8:43:48 PM: error during build:
8:43:48 PM: Error: Build failed with 2 errors:
8:43:48 PM: .svelte-kit/output/server/chunks/db.js:40:11: ERROR: Top-level await is not available in the configured target environment ("es2020")
8:43:48 PM: .svelte-kit/output/server/chunks/db.js:47:0: ERROR: Top-level await is not available in the configured target environment ("es2020")
8:43:48 PM:     at failureErrorWithLog (/opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:1566:15)
8:43:48 PM:     at /opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:1024:28
8:43:48 PM:     at /opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:969:67
8:43:48 PM:     at buildResponseToResult (/opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:1022:7)
8:43:48 PM:     at /opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:1134:14
8:43:48 PM:     at responseCallbacks.<computed> (/opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:671:9)
8:43:48 PM:     at handleIncomingPacket (/opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:726:9)
8:43:48 PM:     at Socket.readFromStdout (/opt/build/repo/node_modules/@sveltejs/adapter-netlify/node_modules/esbuild/lib/main.js:647:7)
8:43:48 PM:     at Socket.emit (node:events:513:28)
8:43:48 PM:     at addChunk (node:internal/streams/readable:324:12)
8:43:48 PM: ​
8:43:48 PM: ────────────────────────────────────────────────────────────────
8:43:48 PM:   "build.command" failed                                        
8:43:48 PM: ────────────────────────────────────────────────────────────────

System Info

My OS has no impact here, how would I get this info from netlify?

Severity

blocking an upgrade

Additional Information

Unable to deploy the site currently.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kirkbushellcommented, Oct 18, 2022

What’s the config of your adapter, i.e. how does your svelte.config.js look like? If there’s edge: true in it, that’s the reason: most edge environments (Netlify etc) do NOT support top level await yet.

Mate, you hit the nail on the head - the issue was the edge: true configuration. There’s no way I would have worked that out lol

Ty so much for your time and help today - you are a gentleman and a scholar.

0reactions
dummdidummcommented, Oct 18, 2022

What’s the config of your adapter, i.e. how does your svelte.config.js look like? If there’s edge: true in it, that’s the reason: most edge environments (Netlify etc) do NOT support top level await yet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Top-level await is not available in the configured target ...
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/Β ......
Read more >
Get error to build my project in Vite - Top-level await is not ...
but when I run to build it I get an error. error message: Top-level await is not available in the configured target environment...
Read more >
[ERROR] Top-level await is not available in the configured ...
I am getting an error that I'm using a feature not supported in Node v14. However, I'm not using Node v14, but v16....
Read more >
Content Types - ESBuild
Some file extensions already have a loader configured for them by default, ... Note that while transforming code containing top-level await is supported,Β ......
Read more >
Avoid these issues when using new ECMAScript modules in ...
Using the top level await (in typescript). An await is typically called in an async function. There is no way to have one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found