Cannot find type definition file for 'jest'
还没有人认领这个 Issue。
- 主要语言
- C++
- 星标
- 127k
- 派生
- 25.3k
- 平均合并
- 1 天 23 小时
- 30 天内合并 PR
- 4
描述
Description
In a very minimal package declaring a dependency on react-native and the @react-native/typescript-config (such as a very simple library), extending the @react-native/typescript-config yields:
error TS2688: Cannot find type definition file for 'jest'.
The file is in the program because:
Entry point of type library 'jest' specified in compilerOptions
This happens because the tsconfig declares "types": ["jest"], while neither "react-native" nor "@react-native/typescript-config" declare a dependency on neither jest nor @types/jest.
I'd suggest moving the "types": ["jest"], to the template's tsconfig: https://github.com/react-native-community/template/blob/d2a0bee199b49611ee252dd5d7626f10a714bebd/template/tsconfig.json#L2 since that's the package bringing the jest dependency.
Steps to reproduce
Init a new package with this package.json
{
"name": "react-native-ts-test",
"private": true,
"version": "0.1.0",
"scripts": {
"build": "tsc --noEmit"
},
"devDependencies": {
"@react-native/typescript-config": "^0.81.1",
"typescript": "^5.9.2"
},
"dependencies": {
"react-native": "^0.81.1"
}
}
and this tsconfig.json
{
"extends": "@react-native/typescript-config",
"include": ["src/index.ts"]
}
Run npx tsc --noEmit 💥
error TS2688: Cannot find type definition file for 'jest'.
The file is in the program because:
Entry point of type library 'jest' specified in compilerOptions
React Native Version
0.81.1
Affected Platforms
Build - MacOS, Build - Windows, Build - Linux
Output of npx @react-native-community/cli info
N/A
Stacktrace or Logs
error TS2688: Cannot find type definition file for 'jest'.
The file is in the program because:
Entry point of type library 'jest' specified in compilerOptions
MANDATORY Reproducer
https://github.com/react-native-community/reproducer-react-native
Screenshots and Videos
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
将 packages/typescript-config/tsconfig.json 与链接的模板 tsconfig.json 和 package.json 文件进行比较,以了解 Jest 类型应当在哪里被预期。然后在最小复现示例中运行 npx tsc --noEmit,验证该配置可用于不含 Jest 依赖的包,并且仍支持模板设置。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- react-native, typescript
- 领域
- mobile-dev, tooling
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 45/100