react / react/react-native

Cannot find type definition file for 'jest'

Open
#53,563 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Author Provided Repro Needs: React Native Team Attention Resolution: PR Submitted
Dominant language
C++
Stars
127k
Forks
25.3k
Avg merge
1d 23h
Merged PRs (30d)
4

Description

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
Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Compare packages/typescript-config/tsconfig.json with the linked template tsconfig.json and package.json files to understand where the Jest types are expected. Run npx tsc --noEmit in the minimal reproducer, then verify the configuration works for a package without Jest dependencies and still supports the template setup.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile-dev, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.