ESM build cannot be imported in Node.js: `dist/` emits extensionless relative specifiers
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- node.js, typescript
- 领域
- build-system
调研方向
ESM 输出由 tsconfig.build.json 生成,该文件将 module 设为 ESNext,将 moduleResolution 设为 bundler,因此 ./api 这类相对导入在 dist/*.js 中保持无扩展名。请先阅读该配置以及 package.json 中的构建脚本,然后运行构建并用 node 导入 dist/index.js 来复现问题。完成的标准是:ESM 版 dist 能在 Node 下加载且不出现 ERR_MODULE_NOT_FOUND,并且 CJS 输出仍然可用。
由索引模型根据 Issue 内容生成。
描述
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/
- 主要语言
- TypeScript
- 星标
- 4
- 派生
- 0
- 平均合并
- 21 天 8 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
相似的 Issue
-
[analytics-core] getQueryParams does not decode `+` as space and truncates values containing `=`未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
amplitude/Amplitude-TypeScript#2179 · 1 条评论 ·
维护者通常 2 天内回复
-
ci good first issue severity: low
难度 2/5 1-3 小时 新手友好度 68/100
TMHSDigital/GH-Arcade#111 ·
-
AsnIntegerConverter.toASN coerces strings with +value, rounding integers outside safe-integer range未关闭
难度 2/5 1-3 小时 新手友好度 78/100
PeculiarVentures/asn1-schema#189 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100