jest-preset-angular: ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/ts-jest-transformer' is not defined by "exports".

πŸ› Bug Report

To Reproduce

Steps to reproduce the behavior:

Just upgrade from jest-present-angular 8.3.1 to 9.0.1 and now I cannot run tests.

Expected behavior

The tests should run.

Link to repo (highly encouraged)

Error log:

# content of error stacktrace :
   Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/ts-jest-transformer' is not defined by "exports" in /home/x/
y/z/node_modules/ts-jest/package.json

      at Object.<anonymous> (node_modules/jest-preset-angular/build/ng-jest-transformer.js:4:31)

envinfo

System:
    OS: WSL2 - Debian

Npm packages:
    jest: 27.0.3
    jest-preset-angular: 9.0.1
    typescript: 4.0.2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 20

Commits related to this issue

Most upvoted comments

I will bring this up to ts-jest, seem like node at 12.20 is required.

Strange that my work uses Node 12.14 can still run, probably cache on CI server.

Had the same issue - turned out to be node version problem - had run with Node v14.6. Hope that helps somebody.

Edit: switching to v14.16.x fixed it.

I have the same problem. After upgrading to the newest version, I get Package subpath './dist/ts-jest-transformer' is not defined by "exports" in C:\Users\name\project\node_modules\ts-jest\package.json.

I’m using Windows & Angular 11.2.13, no nrwl.

As a temporary fix, I can change the content of node_modules\ts-jest\package.json from:

  "exports": {
    ".": "./dist/index.js",
    "./dist/*": "./dist/*.js",
    "./jest-preset": "./jest-preset.js",
    "./presets": "./presets/index.js",
    "./utils": "./utils/index.js",
    "./package.json": "./package.json"
  }

to

  "exports": {
    ".": "./dist/index.js",
    "./dist/*": "./dist/*.js",
    "./jest-preset": "./jest-preset.js",
    "./presets": "./presets/index.js",
    "./utils": "./utils/index.js",
    "./package.json": "./package.json",
    "./dist/ts-jest-transformer": "./dist/ts-jest-transformer.js",
    "./dist/compiler/ts-compiler": "./dist/compiler/ts-compiler.js"
  },

Then it works. So it seems like the wildcard export is not correctly resolved. But I don’t know why the example project works fine.

Spoiler: My Files

setup-jest.ts:

import 'jest-preset-angular/setup-jest';

package.json:

...
  "jest": {
    "preset": "jest-preset-angular",
    "testMatch": [
      "**/+(*.)+(spec).+(ts)"
    ],
    "setupFilesAfterEnv": ["<rootDir>/setup-jest.ts"]
  }

tsconfig.spec.json:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "emitDecoratorMetadata": true,
    "outDir": "./out-tsc/spec",
    "types": ["jest"]
  },
  "include": ["src/**/*.spec.ts", "src/**/*.d.ts"]
}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "importHelpers": true,
    "target": "es2015",
    "module": "es2020",
    "lib": ["es2018", "dom"]
  }
}