Skip to content

28 个 vite/vitest config 用 __dirname,Vite 8 已警告它在未来 major 默认的 configLoader: 'native' 下不受支持 #25949

Open

Description

@yinlianghui

越界发现,记录于 objectstack-ai/objectui#3579(删除死入口 scripts/start-app.mjs)期间 —— 跑 pnpm --filter @object-ui/runner test 时 Vite 打在输出顶上的一条警告。标 finding 不排队:今天没有任何东西是坏的,构建和测试全绿,这只是一条指向未来 major 的预告。之所以值得记一笔:它不是一个文件的问题,是仓库级的一致模式,等 Vite 把默认值翻过去的那天会一次性全线炸,而那时再改就是在一个红着的仓库里改 28 个文件。

事实(对 origin/main @ 6d762da7a 实测)

跑任何一个带 vite config 的包的测试,都会打印:

(!) 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` (vite.config.ts:19:28). Use `import.meta.dirname` instead
Set `VITE_CONFIG_NATIVE_IGNORE_WARNING=true` to suppress this warning.
  • 安装的 Vite:8.2.0。
  • 用 __dirname 的 tracked config 文件:28 个(git grep -ln '__dirname' -- '*vite.config.ts' '*vite.config.mts' '*vitest.config.ts' '*vitest.config.mts'),覆盖 apps/console、根 vitest.config.mts、两个 examples/,以及 packages/ 下 23 个包(components / fields / layout / runner + 19 个 plugin-*)。

也就是说这不是某个包的疏漏,是脚手架模板一路复制出来的统一写法。

为什么现在只是 finding,不是 bug

  • 当前 configLoader 默认仍是打包式加载,__dirname 照常可用,没有任何构建或测试因此失败。
  • 警告本身可以用 VITE_CONFIG_NATIVE_IGNORE_WARNING=true 静音 —— 但静音是把预告删掉,不是把问题解决掉,不建议走这条。

可选方向(不预设结论)

  1. 批量替换成 import.meta.dirname(Node 20.11+ / 22 起可用,本仓 engines.node: ">=22" 满足)。28 个文件的机械改动,可一次做完;顺带让 native configLoader 提前可用。
  2. 只改新文件、存量随手改 —— 成本分摊,但会长期处于两种写法并存的状态,且没有任何机制阻止新文件继续用 __dirname。
  3. 若选方向 1,可考虑补一条 lint/gate 钉住(禁止在 vite/vitest config 里出现 __dirname),否则模板复制会把它再长回来 —— 这一条是让改动不退化的关键,单纯替换一遍过两个月就会有新文件带着旧写法进来。

建议的判断顺序

先确认维护者是否打算跟进 Vite 的 native configLoader。若打算,方向 1 + 方向 3 的 gate 一起做才有意义;若暂不跟进,原样搁置也完全可以接受 —— 这条 issue 的价值就是让它在 Vite 翻默认值时是已知项而不是突发事故。


Generated by Claude Code

Activity

  1. added
    findingRecorded observation — held, not dispatchable until the findings triage round grades it
    on Aug 7, 2026
  2. claude commented on Aug 7, 2026

    @claude
    Contributor

    Findings triage (#4949 discipline) — triage seat Routine trig_01XhwLupWiUBp7GUEigK1RFW, 19:47Z fire. This card had never been graded.

    Verdict: HOLD — finding retained, with an opportunistic restart condition rather than a wait-for-the-fire one.

    Stale-premise check (origin/main @ 0fcd571): count re-measured, not recalled — git grep -ln '__dirname' origin/main -- '*vite.config.ts' '*vite.config.mts' '*vitest.config.ts' '*vitest.config.mts' ⇒ 28 files, matching the body exactly. Nothing has drifted, and nothing is failing: configLoader: 'native' is not the default yet, so this is still a warning about a future major.

    Why hold — and why the hold is not "wait until it breaks". The body's own argument is that the cheap moment is now and the expensive moment is after the flip (28 files in a red repo). That argument is sound and is why the restart condition below is written to fire early rather than at the flip. What it does not establish is urgency this week: nothing is broken, the repo-wide sweep plus the lint pin (direction 3 — without it the scaffold copies __dirname back in, so a bare replacement decays) is a real chunk of work, and objectui's queue is 35 deep. Direction 2 (only new files) is explicitly the worst of the three and should not be the outcome by default.

    Restart conditions:

    1. Early / opportunistic — the next card that edits any vite/vitest config for another reason converts that file to import.meta.dirname in passing (engines.node: ">=22" covers it), so the 28 shrinks without a dedicated claim;
    2. Full promotion — the moment a Vite major that flips configLoader: 'native' enters this repo's dependency range (a bump PR, or the warning becoming an error). At that point this promotes as one sweep card (mechanical, single criterion — the packaged-promotion shape) with the lint pin included, not as 28 separate fixes.

    ⛔ Do not silence the warning with VITE_CONFIG_NATIVE_IGNORE_WARNING=true: that deletes the notice this card depends on.


    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  3. yinlianghui commented on Aug 8, 2026

    @yinlianghui
    ContributorAuthor

    补一条与本单相关的信息(来自 objectstack-ai/objectui#3742 / PR objectstack-ai/objectui#3754,create-plugin 模板),不另开重复单:

    本单的 28 个文件普查漏掉了这个模式的产出源头。 普查用的是 git grep -ln '__dirname' -- '*vite.config.ts' '*vite.config.mts' …,而 create-plugin 生成的 vite.config.ts 是 packages/create-plugin/src/templates.ts 里的字符串字面量,不是 tracked 的 vite.config.ts,所以 grep 扫不到它。本单正文那句判断——「这不是某个包的疏漏,是脚手架模板一路复制出来的统一写法」——诊断是对的,只是计数没把模板本身算进去。

    PR objectstack-ai/objectui#3754 已把模板改成 import.meta.dirname,并加了一条断言钉住(expect(viteConfig).not.toContain('__dirname'))。对本单的影响:存量 28 个文件一个都没动,替换工作量不变;但新生成的插件不会再带着旧写法进来了,即本单「可选方向 3」担心的「模板复制会把它再长回来」这一路已经堵住(仅限 create-plugin 这一条产出路径,不是 lint/gate 级的普遍约束——方向 3 的 gate 依然有它的价值)。

    顺带两条实测补充,可能对本单定级有用:

    1. 在 native 下不是告警而是直接加载失败。 用 vite 8.2.0 自己的 loadConfigFromFile 对同一份 config 按两种 loader 各跑一次:
    # __dirname / bundle
    (!) Your Vite config uses features that are unsupported by `configLoader: 'native'` …
      - `__dirname` (vite.config.old.ts:15:27). Use `import.meta.dirname` instead
    RESULT: LOAD OK
    
    # __dirname / native
    RESULT: LOAD FAILED: __dirname is not defined in ES module scope
    
    # import.meta.dirname / bundle → LOAD OK(无警告)
    # import.meta.dirname / native → LOAD OK
    

    即本单「等 Vite 把默认值翻过去的那天会一次性全线炸」这个判断,现在有了具体的失败文案。

    1. apps/console/vite.config.ts 已在 console vite/vitest configs rely on features configLoader: 'native' drops — a future Vite major turns 5 warnings into a broken config load objectui#3384 转换完毕(该文件现在通篇是 import.meta.dirname,并带了注释说明原因),所以正文里的 28 这个计数对当前 main 可能已经偏高,重新普查一次再定工作量比较准。

    Generated by Claude Code


    Generated by Claude Code

  4. claude commented on Aug 10, 2026

    @claude
    Contributor

    Triage (findings pass): held, premise re-verified on origin/main @ c29ceff — grade unchanged, no ownership taken.

    • Still exactly 28 tracked vite/vitest configs using __dirname (same glob as the card's measurement); installed Vite is ^8.2.1 — the warning-only state persists, nothing red today.
    • Restart condition unchanged: Vite flips configLoader: 'native' to default in a major bump, or a repo-wide scaffold-template sweep that can carry the 28-file mechanical replacement as one batch.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  5. claude commented on Aug 10, 2026

    @claude
    Contributor

    Findings round — held (finding kept), premise re-verified.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  6. os-zhuang commented on Aug 11, 2026

    @os-zhuang
    Contributor

    Findings round — held (finding kept), premise re-verified.

    Re-checked @ objectui origin/main b42558a: still exactly 28 tracked vite/vitest configs using __dirname (same glob census as the card), and the template source (create-plugin) remains converted per PR objectstack-ai/objectui#3754, so the stock is stable, not growing. Held: warning-only today — nothing red until Vite flips configLoader: 'native' to default in a future major; the census here is the ready-made worklist for that day.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  7. os-zhuang commented on Aug 11, 2026

    @os-zhuang
    Contributor

    Findings triage (re-verify @ origin/main f812de6): HOLD — 27 vite/vitest config files still reference __dirname (card filed at 28; one retired since, direction unchanged). Still a forward-compat observation against Vite 8's future configLoader: 'native' default — no current breakage, sweep-shaped fix when taken. finding stands.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  8. claude commented on Aug 11, 2026

    @claude
    Contributor

    Findings cadence re-check @ origin/main 90e792e: HOLD (finding stays). Still exactly 28 vite/vitest config files matching __dirname (counted on the ref, same as at filing). Becomes real at the Vite major that defaults configLoader: 'native'; nothing breaks today.

    本评论来自分诊座位 Routine(#5474 试点),不构成认领。


    Generated by Claude Code

  9. added
    pm:on-holdDecision made, deliberately deferred — no dispatch, no nag; restart condition in the hold comment
    and removed
    findingRecorded observation — held, not dispatchable until the findings triage round grades it
    on Aug 17, 2026
  10. os-project-manager commented on Aug 17, 2026

    @os-project-manager
    Collaborator

    Triage (batch first-touch round, 2026-08-17): finding → pm:on-hold — state transition of the standing 2026-08-07 opportunistic HOLD. Re-verified this round: still exactly 28 tracked configs with __dirname, Vite pinned ^8.2.1 (warning-only), template regrowth already plugged by PR objectstack-ai/objectui#3754's pin, and the 2026-08-08 measurement stands that under configLoader: 'native' this becomes a hard LOAD FAILED, not a warning. The shaped exit is unchanged: one mechanical 28-file sweep + a lint pin, promoted as a single batch card when the trigger fires.

    Restart-when: the workspace's resolved vite major is >= 9 (root package.json / pnpm-lock.yaml), i.e. the configLoader: 'native' default flip ships


    Generated by Claude Code

  11. added
    domain:devxDomain lane — seat card indexed by label:pm:seat
    on Aug 23, 2026
  12. os-zhuang commented on Aug 23, 2026

    @os-zhuang
    Contributor

    Triage: domain:devx (lane only — pm:on-hold untouched). Landing: the 28 vite/vitest configs plus scripts/start-app.mjs — build tooling under a future Vite major's default.

    Routed via the maintainer direct-dispatch channel, this session, verbatim: 「然后 批 4–5」. PM session session_0124Qg8rLvpXnQDwCmpKUmaJ. objectui three-stream split (maintainer 2026-08-21); not a Routine triage fire — the triage seat may re-grade.


    Generated by Claude Code

  13. added
    domain:uiDomain lane — seat card indexed by label:pm:seat
    and removed
    domain:devxDomain lane — seat card indexed by label:pm:seat
    on Oct 22, 2026
  14. objectstack-fleet commented on Oct 26, 2026

    @objectstack-fleet
    Contributor

    Transferred 2026-10-26T05:00Z from objectstack-ai/objectui#3592, with its comments and timeline; the old URL redirects here. objectui moved into this repository as the ui/ workspace (epic #25677) and is being archived (#25854). The body is left exactly as filed.

    Paths. Read every repository path in the body with a ui/ prefix: apps/console is now ui/apps/console.

    Not found under ui/ or at the root on main e167956e3f: scripts/start-app.mjs; re-check that premise before work starts.

    References. The bare issue numbers in the body were written in objectui and now resolve against this repository by mistake; read them as objectstack-ai/objectui#3579.

    No stale pm:dispatched or assignee to strip.


    Generated by Claude Code

  15. objectstack-fleet commented on Oct 26, 2026

    @objectstack-fleet
    Contributor

    Triage: re-grade — tech-debt · priority:p3 · area:devpath · stays pm:on-hold · triage seat · session_01AavokzJ5DndAwitDXvKy4U · 2026-10-26T06:14Z

    ⛔ Not a claim, ⛔ not a dispatch. Re-grade after the transfer from objectui (#25854). The objectui-only labels (types, sdui, scripts and others) do not exist here, and GitHub dropped them on the move.

    • Nothing is broken today (a Vite 8 warning about a future default), so p3, held as filed. The count (28 configs) was taken in objectui. After the merge the dev re-counts over ui/ and the root.

    Restart-when: a Vite release makes configLoader: 'native' the default, or a PR moves this workspace to a Vite major that warns as an error.


    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

No one assigned

    Labels

    area:devpathThe road — create, dev, verify, publish/install, connect an agent, iteratedomain:uiDomain lane — seat card indexed by label:pm:seatpm:on-holdDecision made, deliberately deferred — no dispatch, no nag; restart condition in the hold commentpriority:p3tech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions