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

asume es module when using top level await #54245

Closed
jimmywarting opened this issue May 14, 2023 · 7 comments
Closed

asume es module when using top level await #54245

jimmywarting opened this issue May 14, 2023 · 7 comments
Labels
Question An issue which isn't directly actionable in code

Comments

@jimmywarting
Copy link
Contributor

I'm faced with this error:

'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module. ts(1375)

when i have code such as await 1

it's not always that i import or export something
And i don't really feel like doing and empty export {} or adding any tsconfig.json or jsconfig.json
i have checkJS + allowJs turned on in my vscode settings and the environment it guesses that it's in is sometimes often wrong.

can you just don't assume that it's okey to use top level await.
I want to disable this lint/rule check completely completely... cuz this one is annoying.

@jcalz
Copy link
Contributor

jcalz commented May 14, 2023

There’s a template you’re supposed to fill out when you open a new issue.

Looks like a duplicate of #37794.

@RyanCavanaugh
Copy link
Member

You can set moduleDetection: force

@RyanCavanaugh RyanCavanaugh added the Question An issue which isn't directly actionable in code label May 15, 2023
@jimmywarting
Copy link
Contributor Author

where in vscode? don't have a tsconfig or a jsconfig file

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'Question' and has seen no recent activity. It has been automatically closed for house-keeping purposes. If you're still waiting on a response, questions are usually better suited to stackoverflow or the TypeScript Discord community.

@jimmywarting

This comment was marked as off-topic.

@jimmywarting
Copy link
Contributor Author

is there a vscode setting for this?
or do i really need a tsconfig?

@TomasHubelbauer
Copy link

Since this is top Google hit for the error message, here is how you can get VS Code to chill about TLA when your runtime supports it (e.g.: Bun) and your IDE is holding you back - and all without the dreaded export {}:

tsconfig.json

{
  "compilerOptions": {
    "module": "ESNext",
    "moduleDetection": "force",
    "target": "ESNext"
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Question An issue which isn't directly actionable in code
Projects
None yet
Development

No branches or pull requests

5 participants