I'm getting this error when trying to run a new test:
error TS1378: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.
But server/tsconfig.json already has:
{
"compilerOptions": {
"target": "ES2022",
"esModuleInterop": true,
"module": "ES2022",
"strictNullChecks": true,
"allowSyntheticDefaultImports": true,
"lib": ["ES2021.String"],
"moduleResolution": "node",
"composite": true /* Enable project compilation https://www.typescriptlang.org/docs/handbook/project-references.html */
},
"references": [
{
"path": "../src"
},
{
"path": "../shared"
}
]
}
My Jest test looks like:
test('something', async () => {
await updateTransactions();
// ...
}
and updateTransactions.ts looks like:
const connectionString = process.env.POSTGRESQL_CONNECTION_STRING;
const pgClient = new pg.Client({ connectionString });
await pgClient.connect();
export async function updateTransactions() {
// ...
}
I've already looked at questions like Top-level ‘await’ expressions are only allowed when the ‘module’ option is set to ‘esnext' and How can I use async/await at the top level?
I know that I could refactor await pgClient.connect();
to be within a function, but for various reasons, I'm curious how to just enable top-level await instead.