Relative imports in files inside folders resolve from src/ instead of the importing file

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

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

評価

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

調査の方向性

Start in src/output/moduleCompiler.ts, in processModule, where local specifiers are rewritten with source.replace(/^./+/, 'src/') and only the './' prefix is checked for ImportDeclaration, ExportNamedDeclaration and dynamic import(). Resolve './' and '../' against the directory of the importing filename and normalize '.' and '..' segments. Done when the components/c.js and '../d.js' cases in the issue compile to the correct module keys, which you can check by reproducing them in the playground.

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

説明

When a file is placed in a subfolder (for example components/c.js, which FileSelector, setFiles, and Monaco/Volar all accept), relative imports in that file are resolved from src/ instead of from the importing file's directory, and ../ specifiers are not resolved as local modules.

Reproduction
  1. Sibling ./d.js in components/c.js:

App.vue

<script setup>
import { y } from './components/c.js'
</script>

<template>
  <h1>{{ y }}</h1>
</template>

components/c.js

import { z } from './d.js'
export const y = z

components/d.js

export const z = 'from components/d.js'
  1. Same setup when d.js (export const z = 'from src/d.js') also exists at root:

  2. Parent ../d.js in components/c.js importing root d.js:

Actual
  1. Preview fails with File "./d.js" does not exist..
  2. When src/d.js also exists, components/c.js compiles to const __import_1__ = __modules__["src/d.js"] and silently renders from src/d.js instead of from components/d.js.
  3. With import { z } from '../d.js', the import statement is left untouched in src/components/c.js, src/d.js is not compiled, and the preview stays blank (export { z as y } from '../d.js' emits __export__(__module__, "y", () => z), and export * from '../d.js' throws File "../d.js" does not exist.).
Expected

Relative specifiers (./ and ../, including re-exports and dynamic import()) resolve against the directory of the importing filename and normalize . and .., so ./d.js in src/components/c.js resolves to src/components/d.js and ../d.js resolves to src/d.js.

Cause

In src/output/moduleCompiler.ts, processModule rewrites local specifiers with source.replace(/^\.\/+/, 'src/') without using filename's directory, and only checks source.startsWith('./') for ImportDeclaration, ExportNamedDeclaration, and dynamic import().

Versions

@vue/[email protected] and main (59212b9), [email protected] (verified on play.vuejs.org, repl-vuejs.vercel.app in Chromium 156, and Node v26.13.0).

Credit: https://ucsbplse.github.io/

主要言語
TypeScript
スター
1.1k
フォーク
222
平均マージ
2時間 10分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

vuejs/repl のほかの issue

vuejs/repl の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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