ESM build cannot be imported in Node.js: `dist/` emits extensionless relative specifiers
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- build-system
Research direction
The ESM output is produced by tsconfig.build.json, which sets module to ESNext and moduleResolution to bundler, so relative imports like ./api stay extensionless in dist/*.js. Start by reading that config and the build script in package.json, then reproduce by running the build and importing dist/index.js with node. Done means the ESM dist loads under Node without ERR_MODULE_NOT_FOUND, and the CJS output still works.
Written by the indexing model from the issue text.
Description
Importing @craftycodie/cstruct in a Node.js ES module fails at load time with ERR_MODULE_NOT_FOUND, whereas require("@craftycodie/cstruct") works via dist-cjs/index.js.
npm init -y && npm install @craftycodie/[email protected]
node --input-type=module -e 'import { c } from "@craftycodie/cstruct"; console.log(c.sizeof(c.struct({ x: c.u8() })));'
Actual output:
Error [ERR_MODULE_NOT_FOUND]: Cannot find module '.../node_modules/@craftycodie/cstruct/dist/api' imported from .../node_modules/@craftycodie/cstruct/dist/index.js
Expected output:
1
tsconfig.build.json compiles the ESM output with "module": "ESNext" and "moduleResolution": "bundler", so tsc preserves extensionless relative and directory specifiers (such as "./api" and "./field-types") in dist/*.js, which Node's ESM resolver rejects.
Versions tested: @craftycodie/[email protected] and main (9421e72), Node.js v26.13.0.
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 4
- Forks
- 0
- Avg merge
- 21d 8h
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing 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.
Similar issues
-
[analytics-core] getQueryParams does not decode `+` as space and truncates values containing `=`Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
amplitude/Amplitude-TypeScript#2179 · 1 comment ·
Maintainers usually reply within 2 days
-
ci good first issue severity: low
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
TMHSDigital/GH-Arcade#111 ·
-
AsnIntegerConverter.toASN coerces strings with +value, rounding integers outside safe-integer rangeOpen
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
PeculiarVentures/asn1-schema#189 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100