Skip to content

Parsing error: Cannot use keyword 'await' outside an async function #199

@zenflow

Description

@zenflow

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I'm using eslint-plugin-vue.
  • I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-vue repo and open the issue in eslint-plugin-vue repo if there is no solution.
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.

What version of ESLint are you using?

8.41.0

What version of eslint-plugin-vue and vue-eslint-parser are you using?

  • vue-eslint-parser@9.3.0
  • eslint-plugin-vue@0.0.0

What did you do?

Configuration
{
  "extends": [
    "zenflow"
  ],
  "parser": "vue-eslint-parser"
}
<template>
  <div>{JSON.stringify(posts)}</div>
</template>
<script lang="ts" setup>
const posts = await getPosts()
</script>

What did you expect to happen?

I expected my Vue SFC to be parsed without issues, since:

1

Top-level await can be used inside <script setup>.
-- https://vuejs.org/api/sfc-script-setup.html#top-level-await

2

The code actually works fine, as expected (I can use the component within <Suspense> which is great).

What actually happened?

$ eslint . --ext .js,.ts,.vue --fix

C:\Users\matt_\Documents\dev\lucid-chat\components\PostsList.vue
  20:17  error  Parsing error: Cannot use keyword 'await' outside an async function

✖ 1 problem (1 error, 0 warnings)

Link to Minimal Reproducible Example

Available upon request. (I don't think there will be any difficulty seeing or reproducing the particular issue so I didn't include a repro automatically. Sorry if it is actually required for this one.)

Additional comments

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions