Importing a subpath of a scoped runtime package, such as /runtime/v1/@opendatacapture/runtime-core/constants, resolves to a nonexistent .../index.js

クローズ 初心者向け
#1,799 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

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

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
84/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
node.js, typescript
領域
build-system

調査の方向性

packages/instrument-bundler/AGENTS.mdを読み、packages/instrument-bundler/src/plugin.ts:23-26のパスマッチングロジックを調べてください。packages/instrument-bundler/src/__tests__/plugin.test.tsに、スコープ付きサブパス、.jsで終わるサブパス、およびサブパスのないスコープ付きパッケージのケースを追加または更新し、そのユニットテストを実行してください。サブパスは.js付きで解決され、サブパスのないパッケージだけが/index.jsに解決されれば完了です。

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

説明

Area: Instruments Bug Difficulty: Low Good First Issue Priority: Low

The bundler rewrites any import of a subpath of a scoped runtime package to a URL that does not exist. For bare packages, the rule in plugin.ts appends /index.js to /runtime/v1/<pkg> and /runtime/v1/@scope/<pkg>. But its scope group is (@.*\/)?, and .* also matches /, so it swallows any number of path segments. /runtime/v1/@opendatacapture/runtime-core/constants therefore becomes /runtime/v1/@opendatacapture/runtime-core/constants/index.js instead of …/constants.js, and an import that already ends in .js gets /index.js appended after the .js. packages/instrument-bundler/AGENTS.md documents the opposite: only the bare package gets /index.js, and everything deeper gets .js. The import type-checks, because runtime/v1/dist/@opendatacapture/runtime-core/constants.d.ts exists. The bundle then fails to evaluate: on the API the subpath import does not resolve, and in the browser the module 404s. Today this affects FILE_TYPES from /runtime/v1/@opendatacapture/runtime-core/constants, and any future scoped package that ships a subpath.

Where

packages/instrument-bundler/src/plugin.ts:23-26:

        } else if (/\/runtime\/v1\/(@.*\/)?[^/]+$/.test(args.path)) {
          return { external: true, path: `${args.path}/index.js` };
        } else if (args.path.startsWith('/runtime/v1/')) {
          return { external: true, path: args.path.endsWith('.js') ? args.path : `${args.path}.js` };

Reproduce

  1. Bundle an instrument whose index.ts contains import { FILE_TYPES } from '/runtime/v1/@opendatacapture/runtime-core/constants';.

Actual: the bundle contains __import("/runtime/v1/@opendatacapture/runtime-core/constants/index.js") (verified on main), which neither the API nor the browser can load. /runtime/v1/@opendatacapture/runtime-core/constants.js becomes …/constants.js/index.js.
Expected: __import("/runtime/v1/@opendatacapture/runtime-core/constants.js"), which is the file runtime/v1/dist serves.

Tests

packages/instrument-bundler/src/__tests__/plugin.test.ts: it('should append .js to a subpath of a scoped runtime package, so only the bare package resolves to index.js'). Cover @opendatacapture/runtime-core/constants, …/constants.js and the bare @opendatacapture/runtime-core.

e2e: none needed beyond the unit test, since no built-in instrument imports a scoped subpath yet.

Suggested fix

Stop the scope group at one segment and anchor the pattern: /^\/runtime\/v1\/(@[^/]+\/)?[^/]+$/.

主要言語
TypeScript
スター
119
フォーク
19
平均マージ
5日 10時間
マージ済み PR(30日)
36

環境構築

はじめの一歩

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

DouglasNeuroInformatics/OpenDataCapture のほかの issue

DouglasNeuroInformatics/OpenDataCapture の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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