Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error TS2688: Cannot find type definition file for 'testing-library__jest-dom'. #17819

Closed
7 tasks done
rodrigc opened this issue Aug 4, 2024 · 1 comment
Closed
7 tasks done

Comments

@rodrigc
Copy link

rodrigc commented Aug 4, 2024

Describe the bug

I created a new vite project using the react-ts template,
and without modifying any files,
if I tried to build it, it would fail with errors:

error TS2688: Cannot find type definition file for 'testing-library__jest-dom'.
  The file is in the program because:
    Entry point for implicit type library 'testing-library__jest-dom'

Reproduction

https://github.com/rodrigc/vite-js-dom-issue

Steps to reproduce

pnpm create vite@latest example1 --template react-ts
cd example1
pnpm install
pnpm build

System Info

System:
    OS: macOS 14.5
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 11.29 GB / 32.00 GB
    Shell: 5.9 - /usr/local/bin/zsh
  Binaries:
    Node: 22.1.0 - /usr/local/bin/node
    npm: 10.7.0 - /usr/local/bin/npm
    pnpm: 9.6.0 - /usr/local/bin/pnpm
  Browsers:
    Chrome: 127.0.6533.89
    Edge: 127.0.2651.86
    Safari: 17.5
  npmPackages:
    @vitejs/plugin-react: ^4.3.1 => 4.3.1
    vite: ^5.3.4 => 5.3.5

Used Package Manager

pnpm

Logs

Click to expand!
pnpm build

> example1@0.0.0 build /Users/crodrigues/vite-js-dom-issue/example1
> tsc -b && vite build

error TS2688: Cannot find type definition file for 'testing-library__jest-dom'.
  The file is in the program because:
    Entry point for implicit type library 'testing-library__jest-dom'

error TS2688: Cannot find type definition file for 'testing-library__jest-dom'.
  The file is in the program because:
    Entry point for implicit type library 'testing-library__jest-dom'


Found 2 errors.

 ELIFECYCLE  Command failed with exit code 1.

Validations

@rodrigc
Copy link
Author

rodrigc commented Aug 4, 2024

I was able to eliminate this error by doing the following:

  1. pnpm add "@testing-library/jest-dom"

  2. Explicitly add to "types" in tsconfig.app.json and tsconfig.node.json

diff --git a/example1/tsconfig.app.json b/example1/tsconfig.app.json
index d739292..d158e31 100644
--- a/example1/tsconfig.app.json
+++ b/example1/tsconfig.app.json
@@ -21,7 +21,9 @@
     "strict": true,
     "noUnusedLocals": true,
     "noUnusedParameters": true,
-    "noFallthroughCasesInSwitch": true
+    "noFallthroughCasesInSwitch": true,
+
+     "types": ["@testing-library/jest-dom"]
   },
   "include": ["src"]
 }
(venv) vite-js-dom-issue/example1 - [main●] » git diff tsconfig.node.json
diff --git a/example1/tsconfig.node.json b/example1/tsconfig.node.json
index 3afdd6e..3e1280e 100644
--- a/example1/tsconfig.node.json
+++ b/example1/tsconfig.node.json
@@ -7,7 +7,9 @@
     "moduleResolution": "bundler",
     "allowSyntheticDefaultImports": true,
     "strict": true,
-    "noEmit": true
+    "noEmit": true,
+
+    "types": ["@testing-library/jest-dom"]
   },
   "include": ["vite.config.ts"]
 }

Is there a problem with the vite react-ts template, or
the way that @testing-library/jest-dom exports types?

@vitejs vitejs locked and limited conversation to collaborators Aug 5, 2024
@bluwy bluwy converted this issue into discussion #17822 Aug 5, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

1 participant