react-testing-library: Cannot find module 'pretty-format'
@testing-library/reactversion: 10.2.0- Testing Framework and version:
@testing-library/domversion 7.9.0jestversion 25.5.4
- DOM Environment:
jsdomversion 15.2.1reactversion 16.13.1nodeversion 13.6.0typescriptversion 3.9.3
What you did:
Dependabot upgrade of @testing-library/react from 10.0.4 to 10.2.0.
What happened:
In CI, our npm script that invokes tsc --noEmit fails with the following:
➜ assets git:(dependabot/npm_and_yarn/assets/testing-library/react-10.2.0) npx tsc --noEmit
node_modules/@testing-library/react/types/index.d.ts:3:54 - error TS2307: Cannot find module 'pretty-format' or its corresponding type declarations.
3 import {OptionsReceived as PrettyFormatOptions} from 'pretty-format'
~~~~~~~~~~~~~~~
Problem description:
It can’t find pretty-format. I do see pretty-format in my package-lock.json, version 25.5.0. It might be the “corresponding type declarations” that the error is flagging? I notice this line was added in #690, which finagles the type definitions a bit, though I don’t totally understand the PR.
It could be that I’m supposed to update my package-json with a new dependency of some sort?
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 21 (5 by maintainers)
Commits related to this issue
- Add `pretty-format` as devDep Typings use `import {OptionsReceived as PrettyFormatOptions} from 'pretty-format'` Fix #694 — committed to testing-library/react-testing-library by samtsai 4 years ago
- fix: Explicitly install 'pretty-format' Work around for https://github.com/testing-library/react-testing-library/issues/694 — committed to mbta/arrow by losvedir 4 years ago
- fix: export pretty-format from @testing-library/dom ref https://github.com/testing-library/react-testing-library/issues/694 — committed to marcosvega91/dom-testing-library by marcosvega91 4 years ago
- fix: import pretty-format from @testing-library/dom fix #694 — committed to marcosvega91/react-testing-library by marcosvega91 4 years ago
This looks like a missing package dependency in
@testing-library/reactit doesn’t matter that@testing-library/domalready includes it, there is no guarantee that npm will hoist the dependency.I my case I only see the error when running Storybook, but after digging a little bit into the code I see that the problem started to appear after an upgrade of Jest: it seems that Jest is using
v26now, so NPM stops hoisting thev25inside@testing-library/domto avoid conflicts with thev26for Jest.@samtsai I see that you closed the PR https://github.com/testing-library/react-testing-library/pull/705 because of the comment that the depdendency should come from
@testing-library/dom… I think that the PR is correct, and if the concern is ensuring the samepretty-formatversion it should be apeerDependency, but in this case a simple dep is the right intention. @kentcdodds Can you re-consider that PR?A dump of
npm ls pretty-formatin my project:In my case the workaround was to install
pretty-formatdirectly so@testing-library/reactreads it from the parent, but it’s a hack.I think a better solution would be to have DOM Testing Library re-export the types from
pretty-formatand import them from@testing-library/dominstead.@jordisantamaria this is now resolved in version 5.5.2 of vue-testing-library.
So working with your repo, I was able to upgrade to
10.2.0as is.Steps:
node_modulesandpackage-lock.jsonnode_modulesnpx tsx --noEmitI know that removing
package-lock.jsonhas its own risk but we’d like not to have to unnecessarily add dependencies to this project when@testing-library/domalready has it as a dependency.cc @kentcdodds