react / react/react-native

Cannot find type definition file for 'jest'

Abierto
#53,563 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Issue: Author Provided Repro Needs: React Native Team Attention Resolution: PR Submitted
Lenguaje dominante
C++
Estrellas
127k
Forks
25.3k
Merge medio
1 d 23 h
PR fusionados (30 d)
4

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Compara packages/typescript-config/tsconfig.json con los archivos de plantilla vinculados tsconfig.json y package.json para entender dónde se esperan los tipos de Jest. Ejecuta npx tsc --noEmit en el reproductor mínimo y, a continuación, verifica que la configuración funcione para un paquete sin dependencias de Jest y que siga admitiendo la configuración de la plantilla.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
react-native, typescript
Área
mobile-dev, tooling
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.