jest-dom
jest-dom copied to clipboard
Cannot find package 'vitest'
@testing-library/jest-domversion: 6.6.3nodeversion: v22.13.1jest(orvitest) version: 3.0.5npm(oryarn) version: [email protected]
Relevant code or config:
; .npmrc
hoist=false
What you did:
Tried running tests.
What happened:
Error: Cannot find package 'vitest' imported from /path/to/project/ui/node_modules/.pnpm/@[email protected]/node_modules/@testing-library/jest-dom/dist/vitest.mjs
Suggested solution:
vitest is declared in the devDependencies of @testing-library/jest-dom but it must be declared in the dependencies or peerDependencies because @testing-library/jest-dom/dist/vitest.mjs is importing vitests expect at test run time.
I'm getting the same error, someone should patch it up. I ended up downgrading to 6.5
"@testing-library/jest-dom": "6.5"
In case anyone else comes across this before the ghost dependencies are resolved, I was able to fix this when using vitest with pnpm by using their packageExtensions feature to re-enable the peerDependencies for this package. I believe yarn also has a solution for this though I didn't investigate it.
pnpm-workspace.yaml:
packageExtensions:
'@testing-library/jest-dom':
peerDependencies:
jest: '*'
vitest: '*'
For the record, this is a regression caused by the removal of peerDeps from this package and can only be resolved in this repo or with overrides. The src/vitest.js file imports directly from vitest but the package incorrectly omits it from peerDependencies, causing a ghost dependency.
https://github.com/testing-library/jest-dom/blob/e15f7893cda14a493c92511968502331939adef3/src/vitest.js#L3