`@react-native/jest` fails to resolve `react-native` in monorepos
まだ誰も着手していません。
- 主要言語
- C++
- スター
- 127k
- フォーク
- 25.3k
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 4
説明
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
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
必須の rnx-kit 再現環境で、まず @react-native/jest の依存関係メタデータと .yarnrc.yml のワークアラウンドを確認します。ワークアラウンドを削除し、yarn を実行し、build-scope @rnx-kit/test-app を実行してから、packages/test-app でテストを実行し、resolver の失敗を再現します。ワークアラウンドなしでテストが成功し、依存関係が pnpm または pnpm モードの Yarn で機能すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- react-native
- 領域
- mobile, testing
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100