You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been dealing with an issue where I get TSError: ⨯ Unable to compile TypeScript: error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'. when I try to run the tests inside of VS Code using either the run or debug behavior. The tests are working just fine in nx versions 20 or 19 and seems to be related to using the new nodenext module and moduleResolution behavior in version 21.
I dug into this in depth and the issue comes from the jest-config library being used to read the typescript files. The library is being used to read the base jest.config.ts file and also uses the root tsconfig.json file which has the compiler options below:
The problem stems from this line in the jest-config npm package (see below). Because this sets the module to CommonJS, when NX sets the moduleResolution to NodeNext it will always cause the tests to fail. There isn't an easy to override this and it is being updated in jest version 30.
asyncfunctionregisterTsNode(): Promise<Service>{try{// Register TypeScript compiler instanceconsttsNode=awaitimport('ts-node');returntsNode.register({compilerOptions: {module: 'CommonJS',},moduleTypes: {'**': 'cjs',},});}catch(e: any){if(e.code==='ERR_MODULE_NOT_FOUND'){thrownewError(`Jest: 'ts-node' is required for the TypeScript configuration files. Make sure it is installed\nError: ${e.message}`,);}throwe;}}
Expected Behavior
Jest tests should be able to be run using vs code standard extensions. I was able to fix this in my project by creating a javascript jest.config.js file at the root of my project and adding the following override
Error: Jest: Failed to parse the TypeScript config file .../testing-nx-tests/apps/testing-nx-tests-e2e/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 (.../testing-nx-tests/node_modules/@jest/core/node_modules/jest-config/build/readConfigFileAndSetRootDir.js:116:13)
at async readInitialOptions (.../testing-nx-tests/node_modules/@jest/core/node_modules/jest-config/build/index.js:403:13)
at async readConfig (.../testing-nx-tests/node_modules/@jest/core/node_modules/jest-config/build/index.js:147:48)
at async Promise.all (index 0)
at async readConfigs (.../testing-nx-tests/node_modules/@jest/core/node_modules/jest-config/build/index.js:443:27)
at async runCLI (.../testing-nx-tests/node_modules/@jest/core/build/cli/index.js:151:59)
at async Object.run (.../testing-nx-tests/node_modules/jest-cli/build/run.js:130:37)
Package Manager Version
yarn or npm
Operating System
macOS
Linux
Windows
Other (Please specify)
Additional Information
No response
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
Current Behavior
I have been dealing with an issue where I get
TSError: ⨯ Unable to compile TypeScript: error TS5110: Option 'module' must be set to 'NodeNext' when option 'moduleResolution' is set to 'NodeNext'.
when I try to run the tests inside of VS Code using either the run or debug behavior. The tests are working just fine in nx versions 20 or 19 and seems to be related to using the new nodenext module and moduleResolution behavior in version 21.I dug into this in depth and the issue comes from the
jest-config
library being used to read the typescript files. The library is being used to read the base jest.config.ts file and also uses the root tsconfig.json file which has the compiler options below:The problem stems from this line in the jest-config npm package (see below). Because this sets the module to
CommonJS
, when NX sets the moduleResolution toNodeNext
it will always cause the tests to fail. There isn't an easy to override this and it is being updated in jest version 30.Expected Behavior
Jest tests should be able to be run using vs code standard extensions. I was able to fix this in my project by creating a javascript jest.config.js file at the root of my project and adding the following override
GitHub Repo
https://github.com/observstream/testing-nx-test
Steps to Reproduce
npx create-nx-workspace
and use jest as the test runnerNx Report
Failure Logs
Package Manager Version
yarn or npm
Operating System
Additional Information
No response
The text was updated successfully, but these errors were encountered: