user-event
user-event copied to clipboard
moduleResolution: "nodenext" on tsconfig cannot resolve userEvent
Reproduction example
https://codesandbox.io/p/github/ricardo-passthrough/userevent-nodenext-repro/main?layout=%257B%2522activeFilepath%2522%253A%2522%252FREADME.md%2522%252C%2522openFiles%2522%253A%255B%2522%252FREADME.md%2522%255D%252C%2522sidebarPanel%2522%253A%2522EXPLORER%2522%252C%2522gitSidebarPanel%2522%253A%2522COMMIT%2522%252C%2522fullScreenDevtools%2522%253Afalse%252C%2522rootPanelGroup%2522%253A%257B%2522direction%2522%253A%2522vertical%2522%252C%2522type%2522%253A%2522PANEL_GROUP%2522%252C%2522id%2522%253A%2522DEVTOOLS_PANELS%2522%252C%2522panels%2522%253A%255B%257B%2522type%2522%253A%2522PANEL%2522%252C%2522panelType%2522%253A%2522TABS%2522%252C%2522id%2522%253A%2522clgr11t6d00093b6id8cmkdak%2522%257D%255D%252C%2522sizes%2522%253A%255B100%255D%257D%252C%2522tabbedPanels%2522%253A%257B%2522clgr11t6d00093b6id8cmkdak%2522%253A%257B%2522tabs%2522%253A%255B%257B%2522id%2522%253A%2522clgr11t6d00083b6im5ecqgqt%2522%252C%2522type%2522%253A%2522PROJECT_SETUP%2522%257D%255D%252C%2522id%2522%253A%2522clgr11t6d00093b6id8cmkdak%2522%252C%2522activeTabId%2522%253A%2522clgr11t6d00083b6im5ecqgqt%2522%257D%257D%252C%2522showSidebar%2522%253Atrue%252C%2522showDevtools%2522%253Atrue%252C%2522sidebarPanelSize%2522%253A15%252C%2522editorPanelSize%2522%253A50%252C%2522devtoolsPanelSize%2522%253A35%257D
Prerequisites
Setup a tsconfig.json with moduleResolution "nodenext".
Expected behavior
the following code snippet should build:
import userEvent from '@testing-library/user-event';
test('user event', () => {
userEvent.setup();
})
Actual behavior
Line 4 fails with
Property 'setup' does not exist on type 'typeof import("${HOME}/Projects/repro/node_modules/@testing-library/user-event/dist/types/index")'.
User-event version
14.4.3
Environment
No response
Additional context
When running jest, the issue only happens if I set the preset to ts-jest
. When using babel, the test runs fine--you can check on the repo https://github.com/ricardo-passthrough/userevent-nodenext-repro/tree/babel-test.
Clicking through the import in VSCode sends me to node_modules/@testing-library/user-event/dist/types/index.d.ts
.
Hey @ricardo-passthrough, are you still having issues with this? We're running into the same issue with one of our builds. Thanks!
@clarkmcadoo yes. I marked the typescript error with @ts-expect-error
and forced the type of the return from setup()
:
// @ts-expect-error misconfiguration on userEvent types
const user: ReturnType<typeof userEvent.default.setup> = userEvent.setup();
I have absolutely no idea on the impact of the comment, but now the user
returned from setup has the right type, and userEvent.setup()
runs correctly when turned into javascript.
I'm now getting userEvent.default.setup is not a function
, could you share your tsconfig? or is that in the repro?
Still, really excited to get a diff error and some progress so thank you so much!
@clarkmcadoo not actually. I'll see if I can get this to work in the repro
@clarkmcadoo repro