Skip to content

Top-level await is not supported #72

@FloEdelmann

Description

@FloEdelmann

In jiti v1.12.9 (via nuxt 2.15.8), top-level await doesn't seem to be supported, although it is in Node.js v14+.

See also https://v8.dev/features/top-level-await

When starting my Nuxt app (with top-level await in a server middleware ESM module), I get the following error:

 ERROR  ServerMiddleware Error: await is only valid in async function                                                                                                              21:52:20

  const schemas = await Promise.all([
  ^^^^^
  
  SyntaxError: await is only valid in async function
  at new Script (vm.js:102:7)
  at createScript (vm.js:262:10)
  at Object.runInThisContext (vm.js:310:10)
  at g (node_modules/jiti/dist/jiti.js:1:54973)
  at tests/fixture-valid.js:3:44
  at g (node_modules/jiti/dist/jiti.js:1:55111)
  at ui/api/routes/fixtures/from-editor.js:12:21
  at g (node_modules/jiti/dist/jiti.js:1:55111)
  at ui/api/routes.js:3:19
  at g (node_modules/jiti/dist/jiti.js:1:55111)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions