`@react-native/jest` fails to resolve `react-native` in monorepos
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 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 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从必需的 rnx-kit reproducer 中的 @react-native/jest 依赖元数据和 .yarnrc.yml workaround 开始。移除 workaround,运行 yarn,运行 build-scope @rnx-kit/test-app,然后从 packages/test-app 运行测试,以复现 resolver 失败。完成的标准是测试无需 workaround 即可通过,并且依赖关系可在 pnpm 或 pnpm 模式的 Yarn 中正常工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react-native
- 领域
- mobile, testing
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 52/100