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 ("es2020") #7300

Closed
kirkbushell opened this issue Oct 18, 2022 · 12 comments

Comments

@kirkbushell
Copy link

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.

@dummdidumm
Copy link
Member

Top-level await is not implemented in most edge environments yet AFAIK, so there's nothing we can do about that. #6360 for example was necessary to work around waiting for init. The workaround is to either set the build target low enough that top-level-await is transpiled (not sure if possible honestly), or not use it.

@kirkbushell
Copy link
Author

Thanks, @dummdidumm. But I'm not using it - sveltekit's adapter is.

I tried using an earlier version, and ran into separate issues, where I was advised to update.

@kirkbushell
Copy link
Author

Hmmm, interestingly. Figured out how to set my node version to 18.7.0 on netlify, which got me passed that, but now seeing:

4:35:04 PM: error during build:
4:35:04 PM: TypeError: builder.getAppPath is not a function
4:35:04 PM: at adapt (file:///opt/build/repo/node_modules/@sveltejs/adapter-netlify/index.js:67:21)
4:35:04 PM: at adapt (file:///opt/build/repo/node_modules/@sveltejs/kit/src/core/adapt/index.js:16:8)
4:35:04 PM: at Object.closeBundle (file:///opt/build/repo/node_modules/@sveltejs/kit/src/vite/index.js:460:11)
4:35:04 PM: at async Promise.all (index 0)
4:35:04 PM: at async Object.close (file:///opt/build/repo/node_modules/rollup/dist/es/shared/rollup.js:23662:13)
4:35:04 PM: at async Promise.all (index 0)
4:35:04 PM: at async build (file:///opt/build/repo/node_modules/vite/dist/node/chunks/dep-0fc8e132.js:43473:13)
4:35:04 PM: at async CAC. (file:///opt/build/repo/node_modules/vite/dist/node/cli.js:747:9)

This is the exact same error I saw before I did any updates. So now I'm at a bit of a loss.

@dummdidumm
Copy link
Member

Update your SvelteKit version to latest, then that error goes away. As a rule of thumb, whenever you bump your Adapter version to latest, also bump SvelteKit to latest (while we are not 1.0 yet)

@kirkbushell
Copy link
Author

I've done that already - sveltekit is running latest: 1.0.0-next.516

@kirkbushell
Copy link
Author

Updated packages just to be sure, same problem - back at top level await issue.

.svelte-kit/output/server/chunks/db.js:37:11: ERROR: Top-level await is not available in the configured target environment ("es2020")

Really not sure what I'm doing wrong here.

@dummdidumm
Copy link
Member

  • 4:35:04 PM: TypeError: builder.getAppPath is not a function is related to version mismatch of the adapter and the kit version -> bump both to latest, this should go away
  • .svelte-kit/output/server/chunks/db.js:37:11: ERROR: Top-level await is not available in the configured target environment ("es2020") sounds like something inside user code. There's no db.js file inside SvelteKit's code

@kirkbushell
Copy link
Author

kirkbushell commented Oct 18, 2022

@dummdidumm Yeah I get that second bit - that's a good point.

But it -should- be supported in latest ES, no?

It's working fine locally.

@dummdidumm
Copy link
Member

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.

@kirkbushell
Copy link
Author

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.

@aldo-roman
Copy link

@dummdidumm I am also facing this issue even tho I don't have any edge: true.

My svelte config file is:

const config = {
	preprocess: [vitePreprocess({})],

	kit: {
		adapter: adapter({
			pages: 'build',
			assets: 'build',
			fallback: undefined,
			precompress: false,
			strict: true,
		}),
	},
};

Any idea on how to remove this error regarding the top-level await? TY!

@evdama
Copy link

evdama commented Jul 1, 2024

Into that, adapter-vercel still has the problem of not being able to use top-level await
#6360

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

No branches or pull requests

4 participants