eslint complains about 'await' outside an async function, but the code works #12025
-
I have the following code import { MikroORM } from "@mikro-orm/postgresql"
import config from "$lib/mikro-orm.config"
export const orm = await MikroORM.init(config) eslint complains about a I have not enough experience to understand the implications of that message, or if that is just a false-positive, because the code seems to work, despite the error. What should I do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
The error you’re seeing may be due to how eslint is configured. I’m not familiar with eslint configs but I do know that top level await (await outside an async function) is only supported for modern environments https://caniuse.com/?search=top%20level%20await it’s worth reviewing your eslint config or browserlist config to see if ecma2022 or newer is set anywhere otherwise I think it will set rules for older environments? |
Beta Was this translation helpful? Give feedback.
I’m assuming the default eslint config is set to maintain comptibility with older browsers / client devices. If you intend to use more modern javascript features or only on the server, you can simply change the config to allow it or apply an override to files that are suffixed with .server.js, etc. https://eslint.org/docs/latest/use/configure/configuration-files#how-do-overrides-work