How to enable top-level await in typescript? What are the tsconfig settings? I've tried the common ones such as esnext in module and target es2017 or higher. Can the top level await be in a ts file or does it have to be in another file such as mjs or js?
I'm using node and stencil js along with typescript.
I continue to get this error: Module format cjs does not support top-level await. Use the "es" or "system" output formats rather.
In tsconfig ive tried common settings such as esnext in module and target es2017 or higher.
I export to be able to export a object without a promise.
Example
export class Hello{
static async SayHello() {
return new Promise(resolve => { resolve("Hello World")})
}
}
export const hello = await Hello.SayHello();
//in another ts file
import {hello} from 'Hello.ts'
console.log(hello);
Hi!
I created the following files:
package.json
tsconfig.json
src/Hello.ts
src/index.ts
This seems to do the trick.
That being said are you sure that you want to export
SayHelloas a function and not the entire classHello?