0
votes

I am using jest for unit testing in typescript. When setting "type": "module" in the tsconfig.json, i can run my app, but my jest stops working and say "ReferenceError: require is not defined".

const { pathsToModuleNameMapper } = require("ts-jest/utils");

const { compilerOptions } = require("./tsconfig");

const paths = pathsToModuleNameMapper(compilerOptions.paths, { prefix: "<rootDir>/src" });

delete paths["^(.*)$"];

Eslint is giving me "Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser".

1

1 Answers

0
votes

I worked around this by specifying a modified duplicate of the main tsconfig.

Point to the new file in jest's config:

// package.json example

{
  // [...]
  "jest": {
    "globals": {
      "ts-jest": {
        "tsConfig": "tsconfig.test.json"
      }
    }
  }
}

Credit: https://huafu.github.io/ts-jest/user/config/tsConfig