[Bug]: Bundleless CJS output in a `"type": "module"` package cannot import a sibling's default export
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 72/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, node.js, typescript
- 領域
- build-system, tooling
調査の方向性
Start by reproducing the failure with the provided config: build the bundleless CJS and ESM outputs, then run the two Node.js commands from the issue. Trace how Rslib/Rspack rewrites the sibling default import to require("./b.cjs") and handles __esModule interop. Done when both generated outputs print hi for a package with "type": "module".
索引モデルが issue の本文から書いたものです。
説明
Version
System:
OS: Linux 6.1 Debian GNU/Linux 12 (bookworm) 12 (bookworm)
CPU: (64) x64 Intel(R) Xeon(R) CPU @ 2.80GHz
Memory: 217.67 GB / 251.88 GB
Container: Yes
Shell: 5.2.15 - /bin/bash
npmPackages:
@rslib/core: ^1.0.6 => 1.0.6 (@rspack/core 2.3.1, main b6645e20)
Details
With bundle: false and format: "cjs" in a package with "type": "module", Rslib emits .cjs files and rewrites import greet from "./b.js" to require("./b.cjs"). Because the rewritten request ends in .cjs, Rspack applies Node.js CJS interop and treats the default import as module.exports directly. However, ./b.cjs is Rslib's own CJS output compiled from an ES module (exports["default"] = ... with __esModule: true), so the default import resolves to the module exports object instead of exports.default, and calling it throws TypeError: ... is not a function.
The ESM output of the same project works, and the CJS output also works when "type": "module" is removed from package.json (where output files use .js and Rspack checks __esModule).
Reproduce link
https://gist.github.com/trackoor/1d2c98bfe726648fc3b3f3321a8a6f30
Reproduce Steps
In a project with { "name": "lib", "type": "module" } in package.json:
// src/b.js
export default function greet() {
return "hi";
}
// src/index.js
import greet from "./b.js";
export const out = greet();
// rslib.config.mjs
import { defineConfig } from "@rslib/core";
export default defineConfig({
lib: [
{ format: "cjs", bundle: false },
{ format: "esm", bundle: false },
],
source: { entry: { index: "./src/**" } },
});
Run npx rslib build, then run the generated outputs:
node --input-type=module -e 'import { out } from "./dist/index.js"; console.log(out)'
node -e 'console.log(require("./dist/index.cjs").out)'
Actual output:
- ESM (
dist/index.js):hi - CJS (
dist/index.cjs):
TypeError: external_b_cjs_namespaceObject is not a function
(dist/index.cjs emits const external_b_cjs_namespaceObject = require("./b.cjs"); const out = external_b_cjs_namespaceObject();.)
Expected output:
- Both print
hi.
Credit: https://ucsbplse.github.io/
- 主要言語
- TypeScript
- スター
- 1k
- フォーク
- 68
- 平均マージ
- 9時間 13分
- マージ済み PR(30日)
- 52
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
web-infra-dev/rslib のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
web-infra-dev/rslib#2014 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: Proposal to replace @ast-grep/napi with @swc-next/parser in rsbuild-plugin-dts対応中かも @elecmonkey が 5 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 55/100
web-infra-dev/rslib#1996 · リアクション 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Rspack
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
web-infra-dev/rslib#1839 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[Feature]: resolve new URL as entry対応中かも @elecmonkey が 65 日前に担当しました。 オープンRspack
web-infra-dev/rslib#1825 · リアクション 1 件 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
[Bug]: Code execution order changed after bundling再び着手できるかも @JSerFeng が 245 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンRspack
web-infra-dev/rslib#1519 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
web-infra-dev/rslib の issue をすべて見る
似ている issue
-
clawsweeper:needs-maintainer-review clawsweeper:needs-product-decision clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster P2
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
openclaw/openclaw#195577 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
EKKOLearnAI/ekko-studio#3729 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
Supportseal/SupportSeal-app#98 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
eliasstravik/herdr-projects#845 ·
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
cloudflare/skills#279 ·
メンテナーはふだん 1 日以内に返信