testing-library / testing-library/user-event
Crash when importing files from the export "./dist/esm/*.js"
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 258
- PR merge metrics
- No merged PRs in 30d
Description
Reproduction example
.
Prerequisites
- Use the latest version of 14.5.2 of user-event in an esm node module project
- try to import an esm file into your project -
import { FOCUSABLE_SELECTOR } from '@testing-library/user-event/dist/esm/utils/index.js' - Get the following error on build:
Module not found: Error: Default condition should be last one
Expected behavior
The code should be imported successfully
Actual behavior
Get the following error on build: Module not found: Error: Default condition should be last one
User-event version
14.5.2
Environment
Testing Library framework:
"@testing-library/jest-dom": "^6.4.0",
"@testing-library/react": "^14.2.0",
"@testing-library/user-event": "^14.5.2",
JS framework:
node v18.17.1
"module": "es6"
Test environment:
"vitest": "^1.2.2"
DOM implementation:
"jsdom": "^24.0.0"
Additional context
The error is originated in the package.json found in dist. It has this export:
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"require": "./dist/cjs/index.js",
"default": "./dist/esm/index.js"
},
"./dist/cjs/*.js": {
"types": "./dist/types/*.d.ts",
"import": "./dist/esm/*.js",
"default": "./dist/cjs/*.js"
},
"./dist/esm/*.js": {
"types": "./dist/types/*.d.ts",
"default": "./dist/esm/*.js",
"require": "./dist/cjs/*.js"
}
},
and can be fixed by switching the order of the export:
"./dist/esm/*.js": {
"types": "./dist/types/*.d.ts",
"require": "./dist/cjs/*.js",
"default": "./dist/esm/*.js"
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting the package.json export map in dist and reproduce the reported ESM import with the provided Node and Vitest setup. Adjust the ./dist/esm/*.js export ordering so the default condition is last, then confirm the import builds successfully without the condition-order error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 40/100