`@react-native/jest` fails to resolve `react-native` in monorepos
Nessuno ha ancora preso questa issue.
- Lingua principale
- C++
- Stelle
- 127k
- Fork
- 25.3k
- Merge medio
- 1g 23h
- PR unite (30g)
- 4
Descrizione
Description
@react-native/jest fails to resolve react-native in monorepos that use pnpm or Yarn in pnpm mode. @react-native/jest makes direct references to react-native but never declares it as a dependency, hence it cannot find it because the package manager will never install it.
I was going to add react-native as a peer dependency but it looks like this will create a cycle since react-native has a peer dependency on @react-native/jest. Not sure what approach you would prefer here.
This is the workaround we're currently using: https://github.com/microsoft/rnx-kit/blob/18bf2c4c307826d8d075351d1b8aa93387566177/.yarnrc.yml#L37-L40
Steps to reproduce
- Clone https://github.com/microsoft/rnx-kit
- Remove the workaround mentioned above
- Run
yarn - Build dependencies leading up to the test app:
yarn build-scope @rnx-kit/test-app - Run test:
cd packages/test-app; yarn test
React Native Version
0.85.2
Affected Platforms
Other (please specify)
Output of npx @react-native-community/cli info
n/a
Stacktrace or Logs
% yarn test
FAIL test/App.test.tsx
● Test suite failed to run
Cannot find module 'react-native/Libraries/AppState/AppState' from '../../node_modules/.store/@react-native-jest-preset-virtual-2eb6229c53/package/jest/mock.js'
at Resolver._throwModNotFoundError (../../node_modules/.store/jest-resolve-npm-29.7.0-5c36f0eefb/package/build/resolver.js:427:11)
at mock (../../node_modules/.store/@react-native-jest-preset-virtual-2eb6229c53/package/jest/mock.js:15:19)
at Object.<anonymous> (../../node_modules/.store/@react-native-jest-preset-virtual-2eb6229c53/package/jest/setup.js:68:19)
----------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------|---------|----------|---------|---------|-------------------
All files | 0 | 0 | 0 | 0 |
----------|---------|----------|---------|---------|-------------------
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.297 s
Ran all test suites.
MANDATORY Reproducer
https://github.com/microsoft/rnx-kit/tree/tido/bump-react-native
Screenshots and Videos
No response
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con i metadati della dipendenza @react-native/jest e il workaround .yarnrc.yml nel riproduttore obbligatorio di rnx-kit. Rimuovi il workaround, esegui yarn, esegui build-scope @rnx-kit/test-app ed esegui il test da packages/test-app per riprodurre il fallimento del resolver. Il lavoro è completato quando il test passa senza il workaround e la relazione di dipendenza funziona con pnpm o Yarn in modalità pnpm.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- react-native
- Ambito
- mobile, testing
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100