Skip to content

fix(error): enrich INVALID_OPTION filename substitution with chunk context - #9995

Closed
linyiru wants to merge 1 commit into
rolldown:mainfrom
linyiru:fix/9994-filename-substitution-diagnostics
Closed

linyiru wants to merge 1 commit into
rolldown:mainfrom
linyiru:fix/9994-filename-substitution-diagnostics

Conversation

@linyiru

@linyiru linyiru commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #9994.

A build (e.g. a Qwik app) can fail with:

[INVALID_OPTION] Invalid substitution "../node_modules/@builder.io/qwik-city/lib/index.qwik.mjs_entry_ErrorBoundary" for placeholder "[name]" in "chunkFileNames" pattern, can be neither absolute nor relative paths.

The error exposed only the offending string — no hint about which module/chunk/plugin produced it, which is exactly the issue's complaint ("the error doesn't indicate where the problem originates").

Root cause

An emitted or dynamically-imported chunk whose module resolves outside the input base (e.g. inside node_modules) gets a derived [name] like ../node_modules/... (generate_stage's p.relative(input_base)), which FilenameTemplate::render then rejects via is_path_fragment. The diagnostic dropped all the chunk context the call site already had.

Changes

  • Thread the chunk's facade module id + module ids (already available as RollupPreRenderedChunk) into FilenameTemplate::render via a borrowed FilenameSubstitutionContext — only materialized on the error path, so the common (successful) path stays allocation-free.
  • The INVALID_OPTION message now:
    • names the source module — The "[name]" was derived from module: …
    • lists the chunk's modules
    • adds an actionable hint pointing at emitFile's name / chunkFileNames
  • Populate error.id / error.ids (RollupLog interface) so the offending module is programmatically accessible. This also fixes an inconsistency where warnings exposed ids but errors did not.

Before / After

issue question before after
which file caused it? unknown message + error.id
which modules are in the chunk? — error.ids + message
config / plugin / internal? no hint actionable hint

Tests

  • Rust unit test in filename_template.rs covering the enriched message + chunk context.
  • JS integration test (tests/invalid-filename-substitution.test.ts) asserting errors[0].id / errors[0].ids and the message, via a virtual-module reproduction.

Disclosure: this PR was prepared with the assistance of Claude Code (AI). The author reviewed, built, and verified all changes locally (clippy, rustfmt, Rust unit tests, and the JS integration test all pass).

🤖 Generated with Claude Code

@linyiru
linyiru force-pushed the fix/9994-filename-substitution-diagnostics branch from 0366e61 to db68e7b Compare June 27, 2026 20:36
…ntext (rolldown#9994)

When an emitted or dynamically imported chunk resolves to a module outside the
input base (e.g. inside node_modules), its derived `[name]` becomes a relative
`../...` path that rolldown rejects with INVALID_OPTION. The error previously
exposed only the offending string, so users couldn't tell which file or plugin
caused it.

Thread the chunk's facade module id and module ids through
`FilenameTemplate::render` so the error now names the source module, adds an
actionable hint, and populates `error.id` / `error.ids` (the latter also fixes
errors not exposing `ids` while warnings already did).

Also normalize away the new `id`/`ids` fields in the rollup-tests compatibility
harness (`compareError`), since Rollup's INVALID_OPTION errors carry no ids.
@linyiru
linyiru force-pushed the fix/9994-filename-substitution-diagnostics branch from 786040e to 99b5995 Compare June 27, 2026 20:44
@linyiru
linyiru marked this pull request as ready for review June 27, 2026 22:05
@codspeed

codspeed Bot commented Jun 27, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing linyiru:fix/9994-filename-substitution-diagnostics (99b5995) with main (e0dfef1)

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

IWANABETHATGUY pushed a commit that referenced this pull request Jul 23, 2026
## Description

Fixes #9994.

Rolldown accepts a path-like `name` for an emitted chunk and only fails
later during rendering, with an `INVALID_OPTION` error that carries no
plugin or hook attribution and blames the `chunkFileNames` pattern even
when the pattern contains no `[name]`. Full diagnosis with repros:
#9994 (comment)

Asset names are already rejected at emit time by the native
`FileEmitter`, but the failure surfaces with `pluginCode:
'INVALID_OPTION'` instead of rollup's `VALIDATION_ERROR`, which is why
rollup's `invalid-asset-name` tests sat in the ignored list.

Rollup rejects both synchronously inside `emitFile()`, so the failure
surfaces with `plugin`, `hook`, `code: 'PLUGIN_ERROR'` and `pluginCode:
'VALIDATION_ERROR'` pointing at the plugin that emitted it. This PR
ports that behavior to the JS plugin context: `emitFile` validates
`fileName || name` with rollup's `isPathFragment` predicate and throws
rollup's message. Because it throws inside the hook, the error picks up
plugin and hook attribution with no extra plumbing. Chunks gain
validation they previously lacked; assets gain rollup's error shape.

## Alternatives explored

#9995 enriches the render time error with chunk context, which is
complementary rather than overlapping: it covers name sources that never
pass through the JS `emitFile`. Extending the existing native
`FileEmitter` asset validation to chunks would also work, but the
synchronous throw semantics and the hook error wrapping that provides
attribution live on the JS side, and rollup's own tests assert the
synchronous behavior and the `VALIDATION_ERROR` plugin code.

## Tests

The existing `plugin/context/emit-file-invalid-name` fixture gains the
chunk case and a subdirectory-name negative case (`sub/dir/asset.txt`
still works).

The second commit un-ignores rollup's `emit-file@invalid-asset-name` and
`emit-file@invalid-asset-name3` in `ignored-by-unsupported-features.md`,
which assert exactly this behavior including `pluginCode:
'VALIDATION_ERROR'`. Both pass, including the Windows drive letter
variant, which validates the name string regardless of host OS. Full JS
suite and the rollup compatibility suite are green locally, with a
baseline run on main confirming no behavior change outside the new
validation.
@hyfdev hyfdev self-assigned this Nov 6, 2026
@hyfdev

hyfdev commented Nov 6, 2026

Copy link
Copy Markdown
Member

#9994 was resolved by #10377, which rejects an invalid chunk name inside emitFile and reports the plugin and hook.

Closing this. Thanks for working on this!

@hyfdev hyfdev closed this Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build error provides insufficient diagnostics (INVALID_OPTION in chunkFileNames)

2 participants