Open ruluva opened 3 years ago
@ruluva appreciate you filing this; We've had some other feedback around this kind of scenario & have started to consider enhancements/options to resolve this in a nice way (ref: see this drafted PR in our npm/rfcs
repo). In the meantime, you can work around this problem by using either --legacy-bundling
or the --global-style
flags to help nest your deps & ensure they don't conflict (this, unfortunately, means many deps won't be deduped across your workspaces - again, we're working on a solution for that)
Current Behavior:
I have a project using multiple workspaces. For simplicity I created a smaller project that reproduces the issue. I am using @testing-library/react to help with some unit tests, and I have pulled in the required peer dependencies of react and react-dom. Each package is using its own version of React, one is using 17.0.1 and the other 17.0.2. Both are using the same @testing-library/react package version. The hoisted packages are react (17.0.2), react-dom (17.0.2) and @testing-library/react (11.2.5). Package b has its own React versions for react and react-dom in its local node_modules. I have both projects using the @testing-library/react render function in a set of test files. When I run jest on project a, it passes without issue. When I run jest on project b (with its local versions), it fails with the following error:
FAIL tests/components/App.test.tsx ● Console
● Testing render
So the @testing-library/react packages seems to be referencing the root level React versions, which cause an issue with the local versions.
Expected Behavior:
I expected the @testing-library/react to reference the workspace specific React versions.
Steps To Reproduce:
Package A package.json: "dependencies": { "react": "17.0.2", "react-dom": "17.0.2", }, "devDependencies": { "@testing-library/react": "11.2.5", "react-test-renderer": "17.0.2", }
Package B package.json "dependencies": { "react": "17.0.1", "react-dom": "17.0.1", }, "devDependencies": { "@testing-library/react": "11.2.5", "react-test-renderer": "17.0.1", }
And I created a very simple test for each package:
import { render } from '@testing-library/react'; import { App } from '../../src/components/App';
test('Testing render', () => { const renderedElement = render( );
});
Environment:
OS: MacOS 11.2.3 Node: 14.15.4 npm: 7.7.5