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

Vercel edge middleware targets es2020, which doesn't support top level await #495

Open
1 task
ibodev1 opened this issue Jan 4, 2025 · 9 comments
Open
1 task
Labels
- P2: has workaround Bug, but has workaround (priority) pkg: vercel Related to Vercel adapter (scope)

Comments

@ibodev1
Copy link

ibodev1 commented Jan 4, 2025

Astro Info

Astro                    v5.1.2
Node                     v22.12.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind
                         @astrojs/sitemap
                         astro-robots-txt
                         @astrojs/partytown
                         @astrojs/web-vitals
                         astro:db
                         @astrojs/db/file-url

If this issue only occurs in one browser, which browser is a problem?

Chrome, Brave

Describe the Bug

When I upgraded my project to the latest version of Astro, astro:db started giving errors. The error is available below;

11:13:35 [build] Rearranging server assets...
11:13:35 [@astrojs/vercel] Bundling function ..\..\..\..\dist\server\entry.mjs
✘ [ERROR] Top-level await is not available in the configured target environment ("es2020")

    dist/server/chunks/_astro_db_HwI--WRx.mjs:3:11:
      3 │ const db = await createRemoteDatabaseClient({
        ╵            ~~~~~

11:13:38 [build] Waiting for integration "@astrojs/vercel", hook "astro:build:done"...
Top-level await is not available in the configured target environment ("es2020")
  Location:
    dist/server/chunks/_astro_db_HwI--WRx.mjs:3:11
  Stack trace:
    at failureErrorWithLog (C:\Users\Administrator\Desktop\...\node_modules\esbuild\lib\main.js:1476:15)
    at runOnEndCallbacks (C:\Users\Administrator\Desktop\...\node_modules\esbuild\lib\main.js:1316:45)
    at C:\Users\Administrator\Desktop\...\node_modules\esbuild\lib\main.js:970:16
    at handleIncomingPacket (C:\Users\Administrator\Desktop\...\node_modules\esbuild\lib\main.js:677:12)
    at Socket.emit (node:events:524:28)

I am try to fix astro config;

vite: {
    server: {
      host: true,
      open: true
    },
    build: {
      minify: 'esbuild',
      target: 'es2022'
    }
  }

and with tsconfig.json file;

{
  "extends": "astro/tsconfigs/strict",
  "compilerOptions": {
    "strictNullChecks": true,
    "allowImportingTsExtensions": true,
    "baseUrl": ".",
    "target": "ESNext",
    "paths": {
      "@/*": ["src/*"]
    }
  }
}

But it doesnt working.

What's the expected result?

I am waiting for the project to be built properly and published on the Vercel server.

Link to Minimal Reproducible Example

https://astro.new/repro

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Jan 4, 2025
@florian-lefebvre florian-lefebvre added the needs repro Issue needs a reproduction label Jan 4, 2025
Copy link
Contributor

github-actions bot commented Jan 4, 2025

Hello @ibodev1. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs repro will be closed if they have no activity within 3 days.

@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Jan 4, 2025
@ibodev1
Copy link
Author

ibodev1 commented Jan 4, 2025

@ibodev1
Copy link
Author

ibodev1 commented Jan 4, 2025

@florian-lefebvre

@florian-lefebvre
Copy link
Member

This is not a minimal reproduction but that may be enough for whoever triaging this

@florian-lefebvre florian-lefebvre added needs triage Issue needs to be triaged and removed needs repro Issue needs a reproduction labels Jan 4, 2025
@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

The issue seems to be Vercel edge middleware. If I disable that then it works fine. It currently builds middleware for es2020, but should probably be fine to update, though I'm not 100% sure what the edge runtime supports.

Either way I'll transfer this to the adapters repo and rename

@ascorbic ascorbic transferred this issue from withastro/astro Jan 6, 2025
@ascorbic ascorbic changed the title Top-level await is not available in the configured target environment ("es2020") Vercel edge middleware targets es2020, which doesn't support top level await Jan 6, 2025
@ascorbic ascorbic added - P2: has workaround Bug, but has workaround (priority) pkg: vercel Related to Vercel adapter (scope) and removed needs triage Issue needs to be triaged labels Jan 6, 2025
@ibodev1
Copy link
Author

ibodev1 commented Jan 6, 2025

Vercel Supported Node.js versions

My current vercel node version;
image

Esbuild Supported Targets

I hope I helped :)

@ascorbic
Copy link
Contributor

ascorbic commented Jan 6, 2025

Yeah, that's separate. Edge middleware runs on Cloudflare, but with special settings. It should work, but I'd like to check properly before changing the setting.

@ibodev1
Copy link
Author

ibodev1 commented Jan 8, 2025

Hi @ascorbic , is there any progress on fixing the esbuild issue? Have you checked for compatibility with vercel and cloudflare for trouble-free development?

@ascorbic
Copy link
Contributor

ascorbic commented Jan 8, 2025

@ibodev1 Not yet. If anyone would like to give it a try that could help things along.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) pkg: vercel Related to Vercel adapter (scope)
Projects
None yet
Development

No branches or pull requests

3 participants