Skip to content

Cannot find type definition file for 'jest' #53563

Open

Description

@kraenhansen

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

Activity

  1. react-native-bot commented on Sep 2, 2025

    @react-native-bot
    Collaborator

    Warning

    Missing reproducer: We could not detect a reproducible example in your issue report. Reproducers are mandatory and we can accept only one of those as a valid reproducer:


    You can read more about about it on our website: How to report a bug.

  2. added
    Needs: AttentionIssues where the author has responded to feedback.
    and removed
    Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.
    on Sep 5, 2025
  3. atulgpt17 commented on Sep 5, 2025

    @atulgpt17

    Hi, I am able to repro this issue with the steps mentioned above

  4. cortinico commented on Sep 8, 2025

    @cortinico
    Contributor

    I'd suggest moving the "types": ["jest"], to the template's tsconfig: react-native-community/template@d2a0bee/template/tsconfig.json#L2 since that's the package bringing the jest dependency.

    Yup this feels like a good way forward. Are you up for sending a PR here?
    Also cc @robhogan for visibility

  5. kraenhansen commented on Sep 19, 2025

    @kraenhansen
    ContributorAuthor

    Here's a PR making the use of jest explicit in the template: react-native-community/template#177

    And here's a PR (in draft) to remove it from @react-native/typescript-config: #53855

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions