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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
brandonchinn178 opened this issue Jul 16, 2021 · 4 comments 路 Fixed by #2751
Closed

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

brandonchinn178 opened this issue Jul 16, 2021 · 4 comments 路 Fixed by #2751
Labels
馃悰 Bug Confirmed Bug is confirmed

Comments

@brandonchinn178
Copy link
Contributor

馃悰 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):
@brandonchinn178 brandonchinn178 added Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jul 16, 2021
@brandonchinn178
Copy link
Contributor Author

Workaround: add the following to .yarnrc.yml:

packageExtensions:
  'ts-jest@*':
    peerDependencies:
      'babel-jest': '*'

and rerun yarn install

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 16, 2021

If adding Babel-jest to peer deps, it will make users who don鈥檛 use Babel-jest get the warning too. I think it鈥檚 just yarn 2 problem itself because yarn 1 doesn鈥檛 have this problem.

@brandonchinn178
Copy link
Contributor Author

brandonchinn178 commented Jul 16, 2021

It's not a yarn 2 problem (in it being a regression from yarn 1). PnP forces package.json files to be explicit about all of its dependencies. In this case, this is a correct error (that yarn 1 didn't check) that ts-jest is trying to require a dependency it doesn't explicitly mention in its package.json

peerDependenciesMeta exists for the purpose of marking a peer dependency as optional

"peerDependenciesMeta": {
    "babel-jest": {
        "optional": true
    }
}

@ahnpnl
Copy link
Collaborator

ahnpnl commented Jul 16, 2021

ah ha i never use that optional before. PR is welcome :)

@ahnpnl ahnpnl added 馃悰 Bug Confirmed Bug is confirmed and removed Bug Report Needs Repo Need a minimium repository to reproduce the problem Needs Triage labels Jul 16, 2021
ahnpnl pushed a commit that referenced this issue Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
馃悰 Bug Confirmed Bug is confirmed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants