Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

console vite/vitest configs rely on features configLoader: 'native' drops — a future Vite major turns 5 warnings into a broken config load #3384

Closed

Description

@yinlianghui

Found while working #3305 (wiring apps/console/tsconfig.node.json into a gate). Not fixed there — orthogonal to that change, filing per PD #10. Deliberately left unassigned.

What

Every vite build / vitest run touching the console prints this, once per config load (so it repeats several times in one test run):

(!) Your Vite config uses features that are unsupported by `configLoader: 'native'`,
    which is planned to become the default in a future major version of Vite:
  - `__dirname` (vitest.config.ts:13:33). Use `import.meta.dirname` instead
  - import "./vite.config" without a file extension (vitest.config.ts:4:24). Add the file extension
  - `__dirname` (vite.config.ts:56:35). Use `import.meta.dirname` instead
  - import "../../scripts/vite-crypto-stub" without a file extension (vite.config.ts:6:32). Add the file extension
  - import "../../scripts/vite-maplibre-worker" without a file extension (vite.config.ts:7:36). Add the file extension

Two distinct incompatibilities, both in apps/console:

  1. __dirname in an ESM config — apps/console/vitest.config.ts and apps/console/vite.config.ts. Vite's current (bundling) loader injects a CJS-ish shim; the native loader will not. Replacement is import.meta.dirname.
  2. Extensionless relative imports — vitest.config.ts imports ./vite.config, and vite.config.ts imports ../../scripts/vite-crypto-stub / ../../scripts/vite-maplibre-worker. Node's native ESM resolver does not do extension guessing.

(Line numbers above are from origin/main. On #3305's branch the two scripts/ imports shift to 10/11 because a comment was added above them — the imports themselves are untouched.)

Why it matters

This is dormant today — it is only a warning, and everything builds and tests green, which is why this is filed as a finding rather than a defect. What makes it worth recording is the failure mode when Vite flips the default: the console's config would fail to load, so vite build, vite dev, and the console's whole vitest project all die at once, on a dependency bump rather than on a code change. The fix is mechanical and can be done at any time; the cost of discovering it during an upgrade is a blocked upgrade.

There is also a mild interaction with #3305: apps/console/tsconfig.node.json now type-checks vite.config.ts and the scripts/vite-*.ts plugins, so whoever adds the file extensions has a gate that will confirm the specifiers still resolve. moduleResolution: "bundler" accepts both spellings, so adding .ts extensions there will not upset the type-check either way.

Suggested direction (not decided)

  • __dirname -> import.meta.dirname in both console configs.
  • Add explicit extensions to the three relative config imports.
  • Optionally set configLoader: 'native' explicitly afterwards so the repo pins the behaviour instead of waiting to inherit it, and any regression shows up immediately rather than at the next Vite major.

Activity

  1. yinlianghui commented on Aug 6, 2026

    @yinlianghui
    ContributorAuthor

    发现分诊轮(晋级):摘 finding 换 pm:queue。前提复核 live 且在恶化(__dirname 用点已增至 8+):今天每次构建都在刷警告,机械修;拖到 Vite 升版时才发现就是阻塞项。文件面 apps/console/vite.config.ts + vitest.config.ts。


    Generated by Claude Code

  2. self-assigned this
    on Aug 6, 2026
  3. yinlianghui commented on Aug 6, 2026

    @yinlianghui
    ContributorAuthor

    认领:objectui 分片 PM 并行批第 49 单
    会话:session_01GTRjn8xBqp75dk7kFupVRt
    分支:claude/issue-3384-console-config-native
    Worktree:objectui-issue-3384
    文件面:apps/console/vite.config.ts、apps/console/vitest.config.ts(__dirname→import.meta.dirname、三处相对导入补扩展名)。issue 的可选项采纳:改完显式钉 configLoader: 'native',让回归立刻响而不是等下个 Vite 大版本(若钉上后有实际不兼容,回报为发现,不硬钉)。#3305 接好的 tsconfig.node.json 门用于确认 specifier 仍解析。
    与同批第 50 单(同 app 不同文件:preview-samples.ts)已声明互斥。


    Generated by Claude Code

  4. yinlianghui commented on Aug 6, 2026

    @yinlianghui
    ContributorAuthor

    验收:ACCEPT → PR #3475(并行批第 49 单 + 续作,会话 session_01GTRjn8xBqp75dk7kFupVRt),17/17 检查零失败(Type Check 于伴随修正后转绿;Build & E2E + Bundle Analysis 绿证明 console 真实 vite build 在新配置下通过,不只是能加载)。ready + auto-merge 因 GraphQL 配额排队,恢复即执行。

    复核要点:

    1. 反向验证暴露 issue 低估工作量的事实(Vite 每文件只报首个 __dirname,「5 处警告」实为 39 处改动),dev 用双向证据钉住;两种 loader 下 resolveConfig 输出等价的对照做得扎实。
    2. 两条升级都处置正确:阻塞项(.ts 扩展名需要 allowImportingTsExtensions——issue 前提「bundler 双拼写皆可」为假)经围栏放宽后以实测三选一(noEmit 被 TS6310 挡、rewrite 语义多余、emitDeclarationOnly 干净)落地;pin 裁定因结构性不可执行(configLoader 是 InlineConfig 入参,鸡生蛋)由 PM 撤回,dev 的部分缓解论证(零警告态即绊线)成立。
    3. dev 自报的 stale-checkout 读取事故(首版错误补丁的根因)及其在续作中的复核纠正,处理透明——这正是「核验 main 用 origin/main 不用共享工作树」纪律的又一实证。
    4. 顺带发现 apps/console/vitest.config.ts is type-checked by nothing, and tsconfig.node.json's include lists a file that doesn't exist #3476(vitest.config.ts 在零 tsc 程序内)finding 留池;包内三处同款 extensionless 模式(components/plugin-dashboard/fields)按 dev 建议留作后续横扫候选,记于此不另立单。

    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions