23

I'm experimenting with yarn workspace monorepo. It is consisting of a TestProject created with create-react-app, and a SharedLib1 which is created with create-react-library. TestProject imports code from SharedLib1. The problem being, TestProject uses react-scripts 3.3.0 which is dependent on babel-jest ^24.9.0, while SharedLib1 uses react-scripts-ts ^2.16.0 which is dependent on babel-jest 22.4.4. When running yarn start in TestProject, it complains:

The react-scripts package provided by Create React App requires a dependency:

  "babel-jest": "^24.9.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:

  /monoRepo/node_modules/babel-jest (version: 22.4.4) 

I could disable the error by setting SKIP_PREFLIGHT_CHECK=true in TestProject or manually upgrade the react-scripts inside SharedLib1, but I'd like to know if there's a better way of handling this.

myMonorepo
 -web
   -SharedLib1
     -package.json
   -TestProject
     -package.json
 -package.json

Package.json of myMonoRepo:

{
  "name": "my-mono-repo",
  "version": "0.1.0",
  "private": true,
  "workspaces": [
    "web/*"
  ],
  "nohoist": [
    "**/babel-jest",
    "**/babel-jest/**"
  ]
}

Package.json of myMonoRepo:

{
  "name": "test-proj",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    ...
    "shared-lib-1": "^1.0.0"
  }
}

And the test code App.tsx:

import React from 'react';
import TestComp from 'shared-lib-1';

import './App.css';

const App: React.FC = () => {
  return (
    <div className="App">
      <TestComp text={'aaa'}/>
      Learn React
    </div>
  );
}

export default App;

There is a babel-jest 24.9.0 inside the node_modules of TestProj and another 22.4.4 inside the node_modules of myMonoRepo

2
  • Can you share what locations you find babel-jest at on your filesystem in your multiple node_modules folders? Also can you share the output of yarn why babel-jest?
    – Slbox
    Commented Jan 28, 2021 at 20:36
  • Could you publish a sample minimal project to a public repository? Commented Jan 31, 2021 at 13:12

1 Answer 1

1

This is very similar, if not the same, to an issue opened on the GH repo for create-react-app and you may find additional information there.

That said, you might try moving babel-jest to a devDependency instead of a package dependency. If that does not work, you might try Selective dependency resolutions, where you can force your project to a specific version of babel-jest -

"resolutions": {
   "babel-jest": "^24.9.0",
   "shared-lib-1": "^1.0.0"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.