Skip to content

fix(tsconfig): don't apply tsconfig when resolving imports from virtual modules - #11089

Merged
shulaoda merged 7 commits into
rolldown:mainfrom
rubas:fix-runtime-importer-tsconfig
Oct 28, 2026
Merged

shulaoda merged 7 commits into
rolldown:mainfrom
rubas:fix-runtime-importer-tsconfig

Conversation

@rubas

@rubas rubas commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #11086.

Before

foo/
├── tsconfig.json       # { "extends": "missing-package/tsconfig.json" }
└── bar/
    ├── tsconfig.json   # { "include": ["*.js"] }
    └── main.js         # export const answer = 42
$ cd foo/bar
$ rolldown main.js --platform node -d dist
 ERROR  Build failed with 1 error:

[RESOLVE_ERROR] Could not resolve 'node:module' in \0rolldown/runtime.js
   ╭─[ \0rolldown/runtime.js:1:31 ]
   │
 1 │ import { createRequire } from 'node:module';
   │                               ──────┬──────
   │                                     ╰──────── Tsconfig not found
───╯

The same input builds with --platform browser, with --no-tsconfig, or from a cwd outside the parent folder.

Problem

  • On platform node, the runtime module \0rolldown/runtime.js imports node:module. Resolver::resolve joins this \0 importer onto cwd and calls resolve_file, so oxc_resolver searches for a tsconfig from <cwd>/\0rolldown/ upward.
  • No tsconfig owns the runtime, so the search reads every tsconfig.json above cwd. One that fails to load stops the build, even though no file in the build uses it. Imports from a plugin's \0 virtual module fail the same way, on any platform.

After

} else if importer.to_str().is_some_and(|id| id.starts_with('\0'))
  && matches!(selected_resolver.options().tsconfig, Some(TsconfigDiscovery::Auto))
{
  // A `\0` importer, such as `\0rolldown/runtime.js`, is a virtual module, not a file.
  // `resolve_file` would search for a tsconfig from `<cwd>/<importer>` upward and fail on
  // one that does not load. `resolve` from the same directory skips that search.
  let importer = self.cwd.join(importer);
  selected_resolver.resolve(importer.parent().unwrap_or(&self.cwd), specifier)
} else {
$ rolldown main.js --platform node -d dist
<DIR>/main.js  chunk │ size: 0.07 kB

✔ rolldown v1.2.12 Finished in 41.53 ms
Cause, design, tests

Cause. crates/rolldown_resolver/src/resolver.rs Resolver::resolve. Since #6873, a relative importer is joined onto cwd and passed to resolve_file. resolve_file runs tsconfig auto-discovery (find_tsconfig) before it looks at the specifier, so the error comes back even for a builtin. oxc_resolver skips this search for a non-absolute path such as a virtual module (oxc-project/oxc-resolver#809), but the join onto cwd makes the path absolute.

Design. With auto-discovery on, a \0 importer now resolves with resolve, from the same directory as before. resolve does not run auto-discovery. Everything else keeps resolve_file:

  • A manual tsconfig. It loads one file, so it has no upward search to fail, and resolve_file keeps its choice of a referenced project by file.
  • Other relative importers. A plugin can pass a relative real file as the importer (this.resolve('foo', 'src/bar.ts')), and today virtual:foo.ts gets the paths of the tsconfig at cwd.

The rule is the \0 prefix, which ModuleId also uses to mark a virtual id.

One behavior changes: with auto-discovery, a \0 virtual module no longer gets paths from a tsconfig whose include matches its path under cwd, such as \0virtual:foo.ts next to a tsconfig with the default include. The transform already gives such a module no tsconfig, because options_for_file receives the raw \0 id and oxc_resolver skips it.

Options I did not take:

  • Skip the tsconfig for builtin specifiers. oxc_resolver applies tsconfig paths before its builtin check, so a user file can map node:module or fs today.
  • Special-case only \0rolldown/runtime.js. Imports from a plugin's \0 virtual module hit the same search.

Not in this PR: rolldown_plugin_vite_resolve resolve_raw joins the importer onto root the same way. With tsconfigPaths on, a relative import from a \0 importer reaches it. I can follow up with the same rule there if you want it.

Tests.

  • crates/rolldown/tests/rolldown/issues/11086: platform node, a plain main.js, and a tsconfig.json whose extends does not resolve. On main it fails with the error above.
  • packages/rolldown/tests/fixtures/tsconfig/virtual-module-broken-tsconfig: a plugin's \0virtual:entry imports ./dep.js next to a tsconfig that does not load. On main it fails with Could not resolve './dep.js' in \0virtual:entry (Tsconfig not found).

Checks.

  • cargo test --workspace --exclude rolldown_binding
  • node tests: test:main and test:watcher
  • cargo clippy -p rolldown_resolver -p rolldown --all-targets -- --deny warnings, cargo fmt --all --check, typos, cargo ls-lint, vp check
  • Vite 8.3.2 with environments.ssr.optimizeDeps.include fails in its SSR dependency optimizer with the same error. With this build, vite --force starts and serves the page.

AI disclosure: AI models helped us find this issue, write the change, and review it.

rubas added 3 commits October 2, 2026 12:21
A `\0` importer, such as the runtime module `\0rolldown/runtime.js`, is a virtual module, not a file. `Resolver::resolve` joined it onto `cwd` and called `resolve_file`, so oxc_resolver searched for a tsconfig from `<cwd>/<importer>` upward and failed on any tsconfig there that does not load. On platform node this broke every build through the runtime's `node:module` import.

With auto-discovery, resolve a `\0` importer with `resolve` from the same directory instead. A manual tsconfig keeps the `resolve_file` path.
@rubas rubas changed the title fix: skip tsconfig auto-discovery for importers fix: skip tsconfig auto-discovery for \0 importers Oct 2, 2026
@rubas
rubas marked this pull request as ready for review October 2, 2026 20:36
@codspeed

codspeed Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing rubas:fix-runtime-importer-tsconfig (512b7f2) with main (44d1d31)

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. ↩

A `\0` importer is a virtual module with no location. Resolve its imports from `cwd` with no tsconfig in every mode, matching the transform side, which already gives virtual modules no tsconfig (#10200). In manual mode this also stops the tsconfig's `paths` from redirecting the runtime's `node:module` import, which panicked in `sort_modules`.

Add a manual-mode fixture for that, give the virtual module test an id with a `/` so it checks that relative imports resolve from `cwd`, and update the 11086 snapshot for the `// <id>` markers from #11235.
@shulaoda shulaoda changed the title fix: skip tsconfig auto-discovery for \0 importers fix(tsconfig): don't apply tsconfig when resolving imports from virtual modules Oct 28, 2026

@shulaoda shulaoda left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! I think virtual modules shouldn't use any tsconfig, the same as in the transform phase, so I pushed a commit to tweak it.

@shulaoda
shulaoda merged commit 8a7874f into rolldown:main Oct 28, 2026
32 checks passed
This was referenced Oct 29, 2026
shulaoda added a commit that referenced this pull request Oct 29, 2026
## [1.2.16] - 2026-10-29

### 🚀 Features

- perf-kit: check rendered output against the original build (#11140) by @IWANABETHATGUY
- perf-kit: node/deno server startup mode (#10601) by @IWANABETHATGUY
- perf-kit: browser page-load perf harness for coding agents (#10365) by @IWANABETHATGUY
- devtools: report mode - agent-readable build metrics report (#10364) by @IWANABETHATGUY
- inline-common-chunks: print record factories parenthesized so they compile eagerly (#11282) by @mattlewis92
- fold `'key' in ns` on namespace imports with statically known exports (#11333) by @danielroe
- inline-common-chunks: inline chunks using `import.meta.hot` in dev mode (#11339) by @hyfdev
- support `experimentalInlineCommonChunks` in dev mode (#11335) by @hyfdev
- use `INVALID_TLA_FORMAT` error for Rollup compatibility (#11266) by @sapphi-red

### 🐛 Bug Fixes

- await bundle.close() in loadConfig and clean up every generated config file (#10347) by @Brooooooklyn
- deps: update mimalloc-safe to 0.1.69 (#11376) by @shulaoda
- transform: don't crash when the working directory has been deleted (#11352) by @shulaoda
- import-glob: follow directory symlinks on the wasm binding (#10624) by @hyfdev
- tree-shaking: preserve exported rest bindings from dynamic imports (#11365) by @shuvroroy
- transform: report `tsconfigFilePaths` for a tsconfig resolved through `TsconfigCache` (#11346) by @cainrus
- tsconfig: don't apply tsconfig when resolving imports from virtual modules (#11089) by @rubas
- code-splitting: handle emitted entries the same as `input` entries when placing the runtime (#11353) by @IWANABETHATGUY
- error: make Diagnostic::add_file idempotent (#10610) by @Nic-Polumeyv
- avoid retaining callable builtin callback owners (#10961) by @IWANABETHATGUY
- code-splitting: only host the runtime in a chunk that every consumer's entries load (#11293) by @IWANABETHATGUY
- code-splitting: keep the source order of chunk imports (#11298) by @IWANABETHATGUY
- dev: don't treat a wrapped module's init as a no-op in dev mode (#11334) by @hyfdev
- treat `cwd` as a literal path in relative glob filters (#11291) by @onmax
- deps: update emnapi to 2.0.0-beta.2 and pin `@napi-rs/wasm-runtime` to 1.2.6 (#11292) by @IWANABETHATGUY
- chunk-import-map: hash stable module ids so keys don't depend on the build folder (#11277) by @mandyheg
- respect CPU limits when sizing native runtime workers (#11280) by @Brooooooklyn
- deconflict the namespace of a module without module syntax (#11256) by @IWANABETHATGUY
- code-splitting: rebuild an absorbed dynamic entry's namespace from what its imports read (#11200) by @mattlewis92
- escape line terminators in debug-info comments (#11258) by @IWANABETHATGUY

### 🚜 Refactor

- extract callable builtin hook wrapper (#10964) by @IWANABETHATGUY

### 📚 Documentation

- add an in-depth explanation for inline common chunks (#11239) by @hyfdev

### ⚡ Performance

- incremental cycle check for `avoidRedundantChunkLoads` (#11320) by @IWANABETHATGUY
- avoid copying module code for `renderedLength` and share `chunk.code` across plugins (#11342) by @IWANABETHATGUY
- count UTF-16 lengths with `simd-utf16-len` (#11259) by @IWANABETHATGUY
- don't load consola when importing rolldown (#11257) by @magurotuna

### 🧪 Testing

- dev: cover hot updates that need modules the tab never received (#9647) by @matthewdavis-oai
- dev: add dynamic import rebuild test (#7123) by @sapphi-red
- code-splitting: import file URLs in fresh-process runtime host tests on Windows (#11354) by @shulaoda
- esbuild: mark loader_data_url_base64_invalid_utf8 as an intentional difference (#10790) by @CoderSerio
- watch: fix flaky `watch buildDelay` (#11175) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- install `cmake-core` instead of the `cmake` metapackage on FreeBSD (#11361) by @shulaoda
- deps: update oxc to 0.156.0 (#11326) by @Dunqing
- stop the Discord notification when the metric workflow fails (#11357) by @IWANABETHATGUY
- connect to the Void platform before the docs deploy (#11350) by @shulaoda
- deps: update rust crates (#11297) by @renovate[bot]
- deps: update dependency vite-plus to v1.4.0 (#11288) by @renovate[bot]
- deps: update npm packages (#11296) by @renovate[bot]
- deps: update napi (#11287) by @renovate[bot]
- deps: update rollup submodule for tests to v4.65.1 (#11331) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11332) by @rolldown-guard[bot]
- deps: update dependency rolldown-plugin-dts to v0.28.8 (#11286) by @renovate[bot]
- deps: bump tokio to 1.53.3 (#11317) by @Brooooooklyn

### ❤️ New Contributors

* @mattlewis92 made their first contribution in [#11282](#11282)
* @shuvroroy made their first contribution in [#11365](#11365)
* @cainrus made their first contribution in [#11346](#11346)
* @matthewdavis-oai made their first contribution in [#9647](#9647)
* @rubas made their first contribution in [#11089](#11089)
* @danielroe made their first contribution in [#11333](#11333)
* @onmax made their first contribution in [#11291](#11291)
* @mandyheg made their first contribution in [#11277](#11277)
* @magurotuna made their first contribution in [#11257](#11257)

Co-authored-by: shulaoda <[email protected]>
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.

[Bug]: platform: node build fails when a parent tsconfig does not load (node:module in \0rolldown/runtime.js)

3 participants