Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ferreria23 opened this issue May 31, 2021 · 20 comments

Comments

@ferreria23
Copy link

🐛 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
@ferreria23 ferreria23 added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels May 31, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented May 31, 2021

Hi, would you please try to clear jest cache?

If that doesn’t work, pls provide your repo :)

@ferreria23
Copy link
Author

Hello @ahnpnl ,

I removed the cache from jest but still giving the same error.

Saddly the repo is private and I cannot provide it.

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 31, 2021

would you please check what is the version of ts-jest?

If it is a private repo, would you please make a separate dummy repo to reproduce the issue?

@ferreria23
Copy link
Author

ts-jest version is 27.0.2.

@ahnpnl
Copy link
Collaborator

ahnpnl commented May 31, 2021

Does removing node_modules and reinstall deps help?

Are you using nrwl nx or using angular-builder/jest?

did you finish all the migrations mentioned in CHANGELOG?

I have a sample repo here https://github.com/ahnpnl/jest-angular but I cannot reproduce your problem.

@ahnpnl ahnpnl added 🤷‍♂️ Needs More Info waiting for more information from author of the issue and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jun 1, 2021
@j0nm1
Copy link

j0nm1 commented Jun 1, 2021

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"]
  }
}

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 1, 2021

Are you using yarn or npm? How did you run the upgrade?

@j0nm1
Copy link

j0nm1 commented Jun 2, 2021

I'm using npm 6.14.4 and updated with npm i -D jest-preset-angular@9.0.1

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 2, 2021

Do you have a repo which can be always producible?

@banjankri
Copy link

banjankri commented Jun 2, 2021

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.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 2, 2021

I suppose Node 12.22.1 will also work. jest-preset-angular CI use Node 12.22.1 and Node 14.16.x

@ferreria23
Copy link
Author

My Node version is 12.18.0.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 2, 2021

@ferreria23 would you please try with Node 12.22.1? I see from NodeJs doc mentioned https://nodejs.org/api/packages.html#packages_subpath_patterns was added in 12.20.0

@j0nm1
Copy link

j0nm1 commented Jun 2, 2021

I also had node 12.18.0 installed. After upgrading to 14.17.0 (latest lts) it works fine. Thank you for your help!

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 2, 2021

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.

@ahnpnl ahnpnl added Upstream Bug and removed 🤷‍♂️ Needs More Info waiting for more information from author of the issue labels Jun 2, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 3, 2021

Confirmed that Node < 12.20.0 will get this issue. I could reproduce by switching GitHub action to Node 12.18.0 https://github.com/ahnpnl/jest-preset-angular/runs/2736935738?check_suite_focus=true

@Random90
Copy link

Random90 commented Jun 4, 2021

I have the same issue, while updating from "jest-preset-angular": "7.1.1" to "jest-preset-angular": "^9.0.1".
Node version is v14.5.0 though.

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 4, 2021

Node 12.20.0+ or 14.13.0+, see https://nodejs.org/api/packages.html#packages_subpath_patterns

@thovo
Copy link

thovo commented Jun 4, 2021

I have the same issue on my windows with NodeJS 12.18.3 for a new Angular project, after upgrade to the latest node version, it worked just fine.

ahnpnl added a commit that referenced this issue Jun 5, 2021
ahnpnl added a commit that referenced this issue Jun 6, 2021
ahnpnl added a commit that referenced this issue Jun 6, 2021
ahnpnl added a commit that referenced this issue Jun 6, 2021
ahnpnl added a commit that referenced this issue Jun 6, 2021
ahnpnl added a commit that referenced this issue Jun 6, 2021
@ahnpnl
Copy link
Collaborator

ahnpnl commented Jun 6, 2021

fix in 9.0.2

@ahnpnl ahnpnl closed this as completed Jun 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants