I'm studying Typescript and running into a problem. I want to use the import
and top-level await
but currently, I can only use one at a time.
Here is my config in tsconfig.json
which allows me to use import
"target": "ESNext",
"module": "ESNext"
And this one allows me to use top-level await:
"module":"commonjs"
I added
"type":"module"
to my package.json
Is there any way that I can take advantage of both features? Many thanks.
I'm using Nodejs 16 and Typescript 4.5.5
Yes, you can use both. Here's info to help you reproduce a successful test:
Node.js (LTS) version:
./package.json
:./tsconfig.json
:./src/module.ts
:./src/main.ts
:In your console: