Skip to content

ts-jest warns about babel-jest not installed when used in yarn 2 workspace #2749

@brandonchinn178

Description

@brandonchinn178

🐛 Bug Report

Yarn 2 has workspaces, where you have a top-level package.json, with subdirectories having their own package.json. If a workspace has ts-jest and babel-jest installed, with babelConfig set, ts-jest will warn

ts-jest[versions] (WARN) Module babel-jest is not installed. If you're experiencing issues, consider installing a supported version (>=27.0.0 <28.0.0-0).

even though it actually finds babel-jest correctly (ts-jest.log shows "loaded module babel-jest" log).

Doing some debugging, I printed out the error in get-package-version.ts and saw that it shows the usual Yarn 2 Pnp error:

Error: ts-jest tried to access babel-jest, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: babel-jest (via "babel-jest")
Required by: ts-jest@virtual:cdc2a663889160479555b82f11958bfd85b7d15b045b5582042820fdf488eff146d80f22499fcddb05d9aac4969ca161c3fb96119d941ba1ca3ee741a319bc59#npm:27.0.3 (via .../.yarn/$$virtual/ts-jest-virtual-48f1fd0a1a/0/cache/ts-jest-npm-27.0.3-10e7dc0605-a63f3a8620.zip/node_modules/ts-jest/dist/utils/)

Looks like ts-jest just needs to add babel-jest to its peerDependencies list (docs).

To Reproduce

Steps to reproduce the behavior:

  1. mkdir repro && cd repro
  2. yarn set version berry
  3. yarn init
  4. mkdir foo && touch foo/package.json
  5. Edit package.json to add "private": true and "workspaces": ["./foo"]
  6. yarn workspace foo add jest ts-jest typescript babel-jest @babel/core @types/jest
  7. Edit jest.config.js to enable ts-jest and turn on babelConfig: true
  8. See warning appear

Expected behavior

Warning should not appear.

Link to repo (highly encouraged)

Debug log:

# content of ts-jest.log :

envinfo

System:
    OS:
    Node version:

Npm packages:
    jest:
    ts-jest:
    typescript:
    babel(optional):

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions