`test-utils` is not exported in `package.json`
See original GitHub issueDescribe the bug
Jest 28 started supporting exports
field in package.json
. Imports from react-intersection-observer/test-utils
are not working. Having:
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils';
Test is failing with:
Cannot find module 'react-intersection-observer/test-utils' from 'test.test.tsx'
To Reproduce
Put following in any test, which runs in Jest 28:
import { mockAllIsIntersecting } from 'react-intersection-observer/test-utils';
Or run the following in Terminal in any project that has react-intersection-observer
installed:
node -e 'require("react-intersection-observer/test-utils")'
Node.js fails to find an export:
node:internal/modules/cjs/loader:488
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './test-utils' is not defined by "exports" in /Users/aleks/bynder/paramount/node_modules/react-intersection-observer/package.json
at new NodeError (node:internal/errors:371:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
at packageExportsResolve (node:internal/modules/esm/resolve:692:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at [eval]:1:1 {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Expected behavior
Node.js could import test-utils
.
Additional context
I tried react-intersection-observer 9.1.0 and 9.3.0.
Node.js v16.13.0
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Error: Package path react-dom.development not exported from ...
How do I resolve this, by adding what it is asking in package.json, or even reinstalling all dependencies? Error: Package path react-dom.
Read more >Testing Non-Exported Functions in JavaScript - Samantha Ming
To test exported function, you can simply import it. But what about non-exported functions? Well that's easy too, thanks to Rewire!
Read more >Setup - Testing Library
React Testing Library does not require any configuration to be used. ... + // add the directory with the test-utils.js file, for example:...
Read more >Configuring Jest
The configuration file should simply export an object: ... Jest will run .mjs and .js files with nearest package.json 's type field set...
Read more >moduleDirectories key does not make it possible to import my ...
Then you can import from test-utils in your tests. So, the key take away is that the name of the module from which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for a quick fix and awesome library!
🎉 This issue has been resolved in version 9.3.2 🎉
The release is available on:
Your semantic-release bot 📦🚀