Skip to content

fix: use a relative tsconfig root for the TypeScript checker - #25209

Merged
ZheSun88 merged 1 commit into
mainfrom
relative-dir-vite-checker
Aug 13, 2026
Merged

fix: use a relative tsconfig root for the TypeScript checker#25209
ZheSun88 merged 1 commit into
mainfrom
relative-dir-vite-checker

Conversation

@Artur-

@Artur- Artur- commented Aug 13, 2026

Copy link
Copy Markdown
Member

vite-plugin-checker builds the tsc command line as a string and splits it on spaces, so the absolute "-p " argument breaks type checking when the project directory contains a space. Vite is always started with the project root as its working directory, both for the production build and for the dev server, so a relative "." resolves to the same tsconfig.json without introducing a splittable argument.

vite-plugin-checker builds the tsc command line as a string and splits it
on spaces, so the absolute "-p <root>" argument breaks type checking when
the project directory contains a space. Vite is always started with the
project root as its working directory, both for the production build and
for the dev server, so a relative "." resolves to the same tsconfig.json
without introducing a splittable argument.
@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 1 450 files  ±0   1 451 suites  ±0   1h 29m 11s ⏱️ + 3m 21s
10 409 tests ±0  10 342 ✅ ±0  67 💤 ±0  0 ❌ ±0 
10 845 runs  ±0  10 777 ✅ ±0  68 💤 ±0  0 ❌ ±0 

Results for commit d099503. ± Comparison against base commit 63992ea.

@ZheSun88
ZheSun88 enabled auto-merge August 13, 2026 06:18
@ZheSun88
ZheSun88 added this pull request to the merge queue Aug 13, 2026
Merged via the queue into main with commit f90a308 Aug 13, 2026
35 checks passed
@ZheSun88
ZheSun88 deleted the relative-dir-vite-checker branch August 13, 2026 06:34
@Dudeplayz

Copy link
Copy Markdown
Contributor

Cross-reference: this change has a side effect that looks unintended — see vaadin/hilla#6040 for the full context.

vite-plugin-checker resolves the project-local TypeScript by handing its root option to createRequire:

// vite-plugin-checker@0.14.5/dist/checkers/typescript/main.js
try {
  const tsEntry = createRequire(path.join(finalConfig.root, "noop.js")).resolve(finalConfig.typescriptPath);
  ...
  tscBin = path.join(dir, "bin", "tsc");
  runWithNode = existsSync(tscBin);
} catch {}
// otherwise:
spawn("tsc", args, { cwd: finalConfig.root, shell: true })

createRequire only accepts an absolute path or a file URL. With root: '.' the argument is relative, so it throws ERR_INVALID_ARG_VALUE, the empty catch swallows it, and the checker falls back to whichever tsc is on PATH rather than the typescript version the project pins:

"."          -> THROW ERR_INVALID_ARG_VALUE
"<abs path>" -> OK .../node_modules/typescript/lib/version.cjs

Reproduced on a minimal Vite 8 project using the generated Vaadin tsconfig.json: with root: '.' a global TypeScript 5.1.3 was picked up and rejected the generated config with TS6046: Argument for '--target' option must be: ... 'es2022', 'esnext' for "target": "es2023". With root as an absolute path the project-local typescript@7.0.2 is used and the same project reports No errors.

So dev-mode type checking currently depends on the developer's PATH, and environments without a suitable global tsc get either a wrong-version diagnostic or no type checking at all.

The argument-splitting problem this PR addresses could be solved without making the path relative — vite-plugin-checker passes -p and the path as separate array elements, so an absolute root only breaks when the checker joins the arguments into a shell string. Keeping root: __dirname and fixing the quoting upstream, or passing typescriptPath explicitly as an absolute path, would preserve local TypeScript resolution.

@Artur-

Artur- commented Aug 16, 2026

Copy link
Copy Markdown
Member Author

If fi3ework/vite-plugin-checker#792 is merged, we can revert to dirname

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants