Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

package.json types/main/module take precedence over conditional exports

オープン
#1,094 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, nodejs, rollup, typescript

調査の方向性

microbundle --target node -f esm --generateTypes=trueを使ってpackage.jsonの例で問題を再現し、その後、結果をtscと比較します。ビルドがpackage.jsonのexportsmainmoduletypesフィールドを、tsconfig.jsonのresolvePackageJsonExportsおよびmoduleResolution設定と併せてどのように処理するかを調査します。条件付きエクスポートによって宣言された型が解決され、ルートのtypesフィールドを必要としなければ完了です。

索引モデルが issue の本文から書いたものです。

説明

Possibly somewhat related to #1085.

Given a package.json:

{
  "main": "./lib/index.cjs",
  "module": "./lib/index.js",
  "type": "module",
  "dependencies": {
    "some-client-with-matching-esm-and-tsconfig": "^x.x.x"
  },
  "exports": {
    ".": {
      "require": {
        "types": "./lib/index.d.ts",
        "default": "./lib/index.cjs"
      },
      "import": {
        "types": "./lib/index.d.ts",
        "default": "./lib/index.js"
      }
    },
    "./package.json": "./package.json"
  },

_without root types property, running:

microbundle --target node -f esm --generateTypes=true

results in error:

(rpt2 plugin) Error: /Users/xxxx/dev/project/dependingclient.ts(197,32): semantic error TS2339: Property 'request' does not exist on type 'DependingClient.ts'.
at RollupContext.error (/Users/xxxx/dev/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20259:3

Indicating it cannot find the types specified in the conditional exports.

Working solution: Specify "types": "./lib/index.d.ts" at root-level.
Also works: Remove the "main" and module property

It seems to me package.json conditional exports are not taking precedence over main/module/types

Not sure if related but when in tsconfig.json resolvePackageJsonExports is explicitly set to true (even weirder is that it would be true by default in node16 moduleresolution) , regardless of whether moduleResolution is set to node16, it throws

rpt2: options error TS5098: Option 'resolvePackageJsonExports' can only be used when 'moduleResolution' is set to 'node16', 'nodenext', or 'bundler'. Whereas running the build simple with tsc causes no issues.

主要言語
JavaScript
スター
8.1k
フォーク
358
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

developit/microbundle のほかの issue

developit/microbundle の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。