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

[Bug]: Compiler error with jest.config.ts and NodeNext moduleResolution in tsconfig.json #14740

Closed
akwodkiewicz opened this issue Dec 4, 2023 · 7 comments · Fixed by #14739
Closed

Comments

@akwodkiewicz
Copy link
Contributor

Version

29.1.2

Steps to reproduce

  1. Create / migrate an existing TS project to moduleResolution: "NodeNext" (with `module: "NodeNext")
  2. Have the jest.config.ts file inside the project
  3. Run Jest

Expected behavior

Correctly parsed Jest config

Actual behavior

Error: Jest: Failed to parse the TypeScript config file /Users/akwodkiewicz/my-repo/jest.config.ts
  TSError: ⨯ Unable to compile TypeScript:
error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.

    at readConfigFileAndSetRootDir (/Users/akwodkiewicz/my-repo/node_modules/@jest/core/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:136:13)
    at async readConfig (/Users/akwodkiewicz/my-repo/node_modules/@jest/core/node_modules/jest-config/build/index.js:216:18)
    at async readConfigs (/Users/akwodkiewicz/my-repo/node_modules/@jest/core/node_modules/jest-config/build/index.js:404:26)
    at async runCLI (/Users/akwodkiewicz/my-repo/node_modules/@jest/core/build/cli/index.js:182:59)
    at async Object.run (/Users/akwodkiewicz/my-repo/node_modules/jest-cli/build/cli/index.js:155:37)

Additional context

The same error happens for "moduleResolution": "Node16" setting:

TS5110: Option 'module' must be set to 'Node16' when option 'moduleResolution' is set to 'Node16'.

and for "moduleResolution": "Bundler"

TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.

Environment

System:
    OS: macOS 14.1
    CPU: (10) arm64 Apple M1 Pro
  Binaries:
    Node: 18.18.2 - /opt/homebrew/opt/nvm/versions/node/v18.18.2/bin/node
    Yarn: 4.0.2 - /opt/homebrew/opt/nvm/versions/node/v18.18.2/bin/yarn
    npm: 9.8.1 - /opt/homebrew/opt/nvm/versions/node/v18.18.2/bin/npm
    bun: 1.0.7 - ~/.bun/bin/bun
@akwodkiewicz
Copy link
Contributor Author

akwodkiewicz commented Dec 4, 2023

Reported for visibility (it's sometimes easier to find an issue rather than a pending PR), because I have created a PR with a fix already.

@soda0289
Copy link

I ran into the same issue using moduleResolution: "bundler"

  TSError: ⨯ Unable to compile TypeScript:
error TS5095: Option 'bundler' can only be used when 'module' is set to 'es2015' or later.

I think this is the same issue: #13350
The issue mentions using TS_NODE_PROJECT environment variable to pass in a different tsconfig to set commonjs and node16 for moduleResoluton which also works. #13350 (comment)

I have not tested your PR #14739 but it makes sense to be using node16 with commonjs and should fix the problem

Copy link

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.

@github-actions github-actions bot added the Stale label Jan 19, 2024
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

1 similar comment
Copy link

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 18, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 20, 2024
@SimenB
Copy link
Member

SimenB commented May 30, 2024

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants