Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
How to have top level await in typescript (switch from commonjs to esnext) without having to change all imports to have .js ending

I would like to have top level await in my typescript nodejs project.

My tsconfig used to look like this:

{
  "compilerOptions": {
    "target": "es2017",
    "module": "commonjs",
    "lib": [
      "dom",
      "es6",
      "es2017",
      "esnext.asynciterable"
    ],
    "skipLibCheck": true,
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",
#### other stuff which I think is not relevant removed ####

And I now switched it to

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "lib": [
      "dom",
      "es6",
      "es2017",
      "esnext.asynciterable"
    ],
    "skipLibCheck": true,
    "sourceMap": true,
    "outDir": "./dist",
    "moduleResolution": "node",
#### other stuff which I think is not relevant removed ####

I have also added "type": "module" to my package.json. Indeed I now have the ability to do top level awaits however

  1. I need to change every import to add the .js file extension
  2. For folders where I added an index.ts to export all the modules I could previously just import the folder name. Now I need to import foldername/index.js
  3. When I auto add an import with vscode it adds it without the .js

The way it is with commonjs is so elegant - can I have the same behaviour with esnext or keep it some other way while gaining top-level await?

about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda