ESM build cannot be imported in Node.js: `dist/` emits extensionless relative specifiers
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- build-system
Hướng nghiên cứu
Đầu ra ESM được tạo bởi tsconfig.build.json, file này đặt module là ESNext và moduleResolution là bundler, nên các import tương đối như ./api vẫn không có phần mở rộng trong dist/*.js. Hãy bắt đầu bằng việc đọc cấu hình này và script build trong package.json, sau đó tái hiện lỗi bằng cách chạy build và import dist/index.js bằng node. Hoàn thành khi dist ESM tải được trên Node mà không gặp ERR_MODULE_NOT_FOUND và đầu ra CJS vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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/
- Ngôn ngữ chính
- TypeScript
- Star
- 4
- Fork
- 0
- Merge trung bình
- 21 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue tương tự
-
[analytics-core] getQueryParams does not decode `+` as space and truncates values containing `=`Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
amplitude/Amplitude-TypeScript#2179 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ci good first issue severity: low
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
TMHSDigital/GH-Arcade#111 ·
-
AsnIntegerConverter.toASN coerces strings with +value, rounding integers outside safe-integer rangeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PeculiarVentures/asn1-schema#189 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100