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

Type import invalid path in build

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
build-system

調査の方向性

まず、src/runtime/server/utils/foo.ts が src/types.ts から Foo をインポートする状態でビルドを再現し、その後 dist に生成された宣言を調べます。出力された ../../../types.js パスと期待される .mts パスを比較し、rollup:done の workaround なしで Foo が TypeScript に認識されることを確認します。

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

説明

Description

Types imported from parent folders have incorrect import paths and do not get recognized by TS due to the incorrect .js extension

Expected Behavior

Type import paths should end with .mts

Reproduction

https://codesandbox.io/p/devbox/l8c85t?file=%2Fdist%2Fruntime%2Futils%2Ffoo.d.ts%3A3%2C1

See the build output in dist. Type Foo imported from src/types.ts in the file src/runtime/server/utils/foo.ts using this import statement import type { Foo } from "../../../types";, got transformed to ../../../types.js which does not have a declaration file, and produces incorrect type.

Workaround

This is how I currently work around this issue.

import fs from 'node:fs'
import path from 'node:path'
export default defineBuildConfig({
  hooks: {
    'rollup:done': function (ctx) {
      const dts = path.resolve(ctx.options.outDir, 'types.d.mts')
      if (fs.existsSync(dts))
        fs.cpSync(dts, path.resolve(ctx.options.outDir, 'types.d.ts'))
    },
  },
})

Related Issue

#308 seems relevant, but I don't know how it's fixed for them

主要言語
TypeScript
スター
277
フォーク
36
平均マージ
2時間 46分
マージ済み PR(30日)
2

環境構築

はじめの一歩

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

nuxt/module-builder のほかの issue

nuxt/module-builder の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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