jest: [Bug]: Declare ts-node as dependency of jest-config

Version

29.7.0

Steps to reproduce

When you have a new project with Jest set up as testing framework and you are using a typescript configuration files you get following error when launching jest tests:

Error: Jest: Failed to parse the TypeScript config file C:\Users\nej\source\repos\ddnp-gui\jest.config.ts
  Error: Jest: 'ts-node' is required for the TypeScript configuration files. Make sure it is installed
Error: Cannot find package 'ts-node' imported from C:\Users\nej\source\repos\ddnp-gui\node_modules\jest-config\build\readConfigFileAndSetRootDir.js
    at readConfigFileAndSetRootDir (C:\Users\nej\source\repos\ddnp-gui\node_modules\jest-config\build\readConfigFileAndSetRootDir.js:116:13)
    at async readInitialOptions (C:\Users\nej\source\repos\ddnp-gui\node_modules\jest-config\build\index.js:403:13)
    at async readConfig (C:\Users\nej\source\repos\ddnp-gui\node_modules\jest-config\build\index.js:147:48)
    at async readConfigs (C:\Users\nej\source\repos\ddnp-gui\node_modules\jest-config\build\index.js:424:26)

Expected behavior

Threre should be no error as typescript configuration is supported according to docs. So expected behaviour is that ts-node should be declared as peerDependency of jest-config. Once ts-node is installed alll works as expected.

Actual behavior

You get error above when running jest tests using typescript configuration, because ts-node is not declared as dependency of jest-config (its only in devDependencies of jest-config).

Additional context

No response

Environment

System:
  OS: Windows 10 10.0.19045
  CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Binaries:
  Node: 20.10.0 - C:\Program Files\nodejs\node.EXE
  npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD
npmPackages:
  jest: ^29.7.0 => 29.7.0

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 4
  • Comments: 16 (1 by maintainers)

Most upvoted comments

yes, the docs mention 2 alternatives - babel and ts-jest (not ts-node), but for babel case it is only mentioned to install @babel/preset-typescript and for ts-jest case its only mentioned to install ts-jest. Nothing about the need to install ts-node. Can than at least the docs be updated to reflect the reality? Also when ts-node is required to be installed for ts-jest alternative to work, should it not be in its peerDependencies? Isn’t that what peerDependencies are for? Or am I missing something?