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

172
Vistas
How to import types in a jestEnvironment?

I'm setting a jest-environment for my tests, and apparently, these environments are not considered as module by Jest. Therefore, I cannot use the ES6 syntax to import and export.

That is why I am trying to find a way to import interfaces or types using require. Is it possible?

This is my jestEnvironment.ts:

import Config = require('@jest/types');
const NodeEnvironment = require('jest-environment-node').default;

class CustomEnvironment extends NodeEnvironment {
  constructor(config: Config.ProjectConfig) {
    super(config);
    console.log(config);
  }

  async setup() {
    await super.setup();
    this.global.someGlobalVar = 'lala';
  }

  async teardown() {
    await super.teardown();
  }

  getVmContext() {
    return super.getVmContext();
  }
}

module.exports = CustomEnvironment;

And when running Jest, I get the following error:

● Test suite failed to run

    /path/to/project/src/jestEnvironment.ts:1
    import { Config } from '@jest/types';
    ^^^^^^

    SyntaxError: Cannot use import statement outside a module

(Just for information: I'm using ts-jest 26.5.6... And I just saw that the version 28 introduced a support to ESM. However, there are too many breaking changes for me to switch to that version for now.)

about 4 years ago · Juan Pablo Isaza
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