-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
[Bug]: jest-config can't import TS file with moduleResolution: node16 #13350
Comments
@Maxim-Mazurok Your script in package.json is incorrect Current "test:integration": "npm run jest -- --config jest.integration.config.ts", Should be "test:integration": "npm run jest --config jest.integration.config.ts", |
No, using You can even see this from log:
Notice how it has And without
You see This is an unrelated matter, perhaps you just didn't notice that I'm not doing One can get the same reproduction by changing import { JestConfigWithTsJest } from "ts-jest";
import integrationConfig from "./jest.integration.config.js";
const config: JestConfigWithTsJest = { ...integrationConfig };
export default config; And then run
Hope that clears it up, cheers! |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Occurring an activity |
Same problem for me. tsc and esbuild work fine, jest can't resolve the import. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
unstaling |
same problem here. Any workarounds? |
Maybe try switching to vitest, same API, even same plugins usually work, but TS and ESM stuff generally works much better with it. |
Excellent tip. I was using vite but didn’t know about vitest! Now “fixed”. And resolve works like a charm. Problem fixed as well. 😜 |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
No worries! Also, unstaling the issue |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Unstale |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
I've migrated to vitest and also using module resolution "bundle" so this issue is no longer relevant to me. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
still the same |
jestjs/jest#13350; also, file renaming and package metadata
I looked at this issue again and found that this was not the case I was having. For this issue, I think you probably need to compile TS jest config ( I don't think jest does any transformations on the config files. |
Why is this being ignored? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
This is still an issue. @SimenB Is there a label that can be added so this doesn't get marked as stale? (it's adding unnecessary "bump" comments that's making it hard to follow along for updates) It looks like
a quick fix would be to update jest-config to also set moduleResolution. Alternatively, respecting any existing tsconfig for the project would be nice. As a workaround, you can create a second tsconfig file for test, e.g. {
"extends": "./tsconfig.json",
"compilerOptions": {
"moduleResolution": "Node10",
"module": "CommonJS",
}
} and then when running jest (I'm using yarn):
|
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Still relevant. |
Still relevant. |
Just ran into this, wondering how jest is used with modern typescript projects using moduleResolution node16? Overriding module resolution for tests would mean you get errors from the base tsconfig.json in your editor, or when validating types using for example |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
Still relevant |
For ESM support in Node.js to work without using extra bundlers or compilers module resolution has to be node16. Otherwise the output generated by If we for example want https://swc.rs/ to generate ESM code we have to use node16 resolution, which basically means swc + jest won't work. |
Still an issue, and testing with @noahnu 's solution did not work for me.. |
This comment was marked as spam.
This comment was marked as spam.
I did not know about this issue and I have submitted a duplicate here half a year ago: #14740 I was able to propose a solution to this issue back then, but the PR is still pending (need help with a test suite or make the decision to ship it without one): #14739 Some help would be appreciated (with the suite, or even letting me know the fix works for you). |
My PR is about the TS config file with modern However, I wanted to suggest a workaround that requires you to add this to the
|
partly addressed in https://github.com/jestjs/jest/releases/tag/v30.0.0-alpha.5 (via #14739) |
Version
29.1.2
Steps to reproduce
git clone https://github.com/Maxim-Mazurok/jest-config-bug-repro
cd jest-config-bug-repro
nvm i
npm ci
tsc --noEmit
- worksnpm run test:unit
- worksnpm run test:integration
- doesn't workExpected behavior
Parse config just fine and exit with
No tests found, exiting with code 0
Actual behavior
gives error:
Additional context
Had to make the switch in https://github.com/Maxim-Mazurok/google-api-typings-generator because sindresorhus/got#2051 (comment)
Environment
The text was updated successfully, but these errors were encountered: