Skip to content

bug(check): vp check --fix <single-file> spurious TS2591 "Cannot find name 'node:X'" for some files #1443

@fengmk2

Description

@fengmk2

Describe the bug

vp check --fix <path/to/file.ts> emits spurious TS2591 errors for node:* imports / process globals on some TS files when given in isolation, while the same files pass when part of a larger batch or a full-project vp check --fix.

This breaks the standard lint-staged pre-commit flow when only a single TS file from the affected directories is staged.

x typescript(TS2591): Cannot find name 'node:util'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig.
   ,-[packages/cli/src/utils/terminal.ts:1:27]
 1 | import { styleText } from 'node:util';
   :                           ^^^^^^^^^^^

The root tsconfig.json has "types": ["node"] and @types/node is installed; the import resolves fine at runtime and in the editor.

Reproduction

On the vite-plus repo itself, current main:

# Fails: TS2591 on the node:util import
vp check --fix packages/cli/src/utils/terminal.ts

# Passes: same file, but as part of a batch of ≥3 files
vp check --fix \
  packages/cli/src/utils/terminal.ts \
  packages/cli/src/version.ts \
  packages/cli/src/config/bin.ts

# Passes: full-project check
vp check --fix

Asymmetry between files

Not every file triggers the bug in isolation. Running vp check --fix <one-file> at repo root:

File Result
packages/cli/src/utils/terminal.ts FAIL
packages/cli/src/utils/help.ts FAIL
packages/cli/src/utils/agent.ts FAIL (5 errors)
packages/cli/src/version.ts FAIL (4 errors)
packages/cli/src/bin.ts PASS
packages/cli/src/config/bin.ts PASS
packages/cli/src/create/bin.ts PASS
packages/cli/src/migration/bin.ts PASS
packages/cli/src/staged/bin.ts PASS

All of these files import from node:* modules. There is no obvious structural difference from the reporter's side.

tsgolint --list-files from the repo root lists every one of the above (both "FAIL" and "PASS" sets) — so the underlying project does include them. The bug appears only when the file is driven into oxlint+tsgolint via a single-file-subset command-line.

Hypothesis

vp check --fix <paths> forwards the paths to oxlint which then fans out to tsgolint. When a single file subset is passed, tsgolint seems to lose the tsconfig's types: ["node"] context for some files. The nearest tsconfig to packages/cli/src/** is packages/cli/tsconfig.json, which has "files": [], "include": [], "exclude": ["**/*"] — effectively excluding the whole package. The root tsconfig.json (which does provide types: ["node"]) is only found if tsgolint walks past the nearest tsconfig when its include set is empty. Whether it walks past seems to depend on which file is passed, which is what makes the behaviour feel like a tsgolint / oxlint-tsgolint project-resolution bug rather than a config issue.

Impact

The default pre-commit hook runs lint-staged → vp check --fix <staged-files>. When a developer stages a single TS file under packages/cli/src/utils/ (or any of the "FAIL" locations above), the commit is blocked by what is not a real type error.

Workarounds

  • Commit with --no-verify (loses all pre-commit validation).
  • Stage at least one additional TS file from a "PASS" directory alongside the change.

Suggested direction

If tsgolint is losing types: ["node"] when invoked on a subset of project files, either:

  1. In oxlint-tsgolint's integration, always resolve the containing tsconfig chain up to the root before invoking tsgolint (even when explicit files are passed).
  2. Or in vp check, if a tsconfig in the resolution chain has "exclude": ["**/*"] / empty include, skip past it to the next ancestor tsconfig.
  3. Or at minimum, expose a stable workaround users can set in vite.config.ts so single-file checks work under lint-staged.

Steps to reproduce

  1. Clone vite-plus and check out current main.
  2. Build and install the global CLI: pnpm bootstrap-cli.
  3. From the repo root: vp check --fix packages/cli/src/utils/terminal.ts.
  4. Observe TS2591 error on line 1.
  5. Re-run: vp check --fix packages/cli/src/utils/terminal.ts packages/cli/src/config/bin.ts packages/cli/src/create/bin.ts.
  6. Observe the same file passes cleanly.

System Info

  • vp v0.0.0 (current main, commit aeb40fc4)
  • oxlint v1.61.0
  • oxlint-tsgolint v0.21.1
  • Node.js v22.18.0
  • macOS arm64 (Darwin 25.2.0)

Used Package Manager

pnpm

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions