Hooks loading `commonjs` files uses `import` condition for `require()`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 122k
- Forks
- 37.3k
- Avg merge
- 4d 2h
- Merged PRs (30d)
- 283
Description
Version
21.5.0
Platform
macOS
Subsystem
No response
What steps will reproduce the bug?
Reproduction: https://github.com/privatenumber/bug-node-hooks-cjs-conditions
How often does it reproduce? Is there a required condition?
A Hook needs to be registered to load commonjs type files.
What is the expected behavior? Why is that the expected behavior?
For the conditions to include require when require(file) is executed.
What do you see instead?
The import conditions only include import.
Here are the logs:
resolve: {
"url": "file:///repro/src/index.cjs",
"context": {
"conditions": [
"node",
"import",
"node-addons"
],
"importAttributes": {}
}
}
load: {
"url": "file:///repro/src/index.cjs",
"context": {
"format": "commonjs",
"importAttributes": {}
}
}
resolve: {
"url": "file:///repro/src/file.cjs",
"context": {
"conditions": [
"node",
"import",
"node-addons"
],
"importAttributes": {},
"parentURL": "file:///repro/src/index.cjs"
}
}
load: {
"url": "file:///repro/src/file.cjs",
"context": {
"format": "commonjs",
"importAttributes": {}
}
}
Additional information
No response
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 with the linked reproduction and inspect the hook resolve and load contexts for CommonJS files. Compare the reported conditions during require(file) with the expected require condition; done means the hook receives the correct condition while loading CommonJS files and the reproduction no longer shows only import.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100