-
Hi guys. I'm using: "@testing-library/user-event": "^14.2.1",
"typescript": "^4.7.4" and IntelliJ as a code editor. If I change import userEvent from '@testing-library/user-event'; I am getting following error message: TS7016: Could not find a declaration file for module '@testing-library/user-event'.
'..../node_modules/@testing-library/user-event/dist/index.cjs' implicitly has an 'any' type.
Try `npm i --save-dev @types/testing-library__user-event` if it exists
or add a new declaration (.d.ts) file containing `declare module '@testing-library/user-event'; I tried both suggestions but any of them doesn't fix the issue. Adding the comment What is the preferred approach for solving this issue? Please advise. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 8 replies
-
The fix, or at least a fix, would be to add "exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/index.cjs",
"default": "./dist/index.mjs"
}
}, See the relevant bit from the TypeScript docs here towards the end of the page. I'd make a Pull Request, but the build script uses @ph-fritsche's external config library, which might not want or need this. |
Beta Was this translation helpful? Give feedback.
-
@ph-fritsche Any change you can give guidance on resolving this? |
Beta Was this translation helpful? Give feedback.
-
Based on this StackOverflow answer, the two features seem to play nice together. Since this package doesn't declare |
Beta Was this translation helpful? Give feedback.
-
Thank you. @4zuko I think this question can be marked as answered now |
Beta Was this translation helpful? Give feedback.
-
Hi all, my create-react-app is failing and claims this is the issue. This is my output w/npm run build: $ npm run build
Creating an optimized production build... babel-preset-react-app is part of the create-react-app project, which Failed to compile. Module not found: Error: Package path ./dist/types/utility/type.js is not exported from package /home/ec2-user/spn/node_modules/@testing-library/user-event (see exports field in /home/ec2-user/spn/node_modules/@testing-library/user-event/package.json) |
Beta Was this translation helpful? Give feedback.
-
I had the same issue and attempted all the suggested solutions. However, I found the comment tagged as the solution a bit unclear, but it found the solution that works for me.
const user = userEvent.setup();
await user.click(/*your code...*/)
await userEvent.click(/*your code...*/) And you're good to go. 👋 |
Beta Was this translation helpful? Give feedback.
Based on this StackOverflow answer, the two features seem to play nice together.
Since this package doesn't declare
typesVersions
, I assume this is a concern of the build script outside of the concerns of this library?