Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

171
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!