Skip to content

tsserver does not load @types/node from nested project typeRoots unless types is explicit #63455

@garysassano

Description

@garysassano

Issue

VS Code's TypeScript language service reports missing Node.js types in a nested TypeScript project even though:

  • TypeScript: Go to Project Configuration opens the nested project's tsconfig.json
  • @types/node is installed under that nested project
  • the nested tsconfig.json has "typeRoots": ["./node_modules/@types"]
  • CLI tsc --noEmit passes

Adding "types": ["node"] fixes the VS Code diagnostic.

Environment

  • VS Code: 1.114.0, arm64
  • TypeScript: 5.9.3
  • OS: macOS 26.4.1
  • Package manager: pnpm 10.33.2

Layout

repo-root/
  nested-project/
    package.json
    tsconfig.json
    node_modules/
      @types/
        node/
    src/
      app.ts

VS Code is opened at repo-root/, not repo-root/nested-project/.

nested-project/package.json

{
  "devDependencies": {
    "@types/node": "^22.19.17",
    "typescript": "~5.9.3"
  }
}

nested-project/tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "CommonJS",
    "lib": ["es2022"],
    "strict": true,
    "esModuleInterop": true,
    "typeRoots": ["./node_modules/@types"]
  },
  "include": ["src/**/*.ts"]
}

nested-project/src/app.ts

import path from "node:path";

export const output = path.join(__dirname, "dist");

Steps

  1. Open VS Code at repo-root/.
  2. Open nested-project/src/app.ts.
  3. Run TypeScript: Go to Project Configuration.
  4. Confirm VS Code opens nested-project/tsconfig.json.
  5. Run TypeScript: Restart TS Server.

Actual

VS Code reports:

Cannot find name 'node:path'. 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. ts(2591)

It may also report missing Node globals such as __dirname.

Expected

Since the active project is nested-project/tsconfig.json, tsserver should load visible packages from:

"typeRoots": ["./node_modules/@types"]

This matches CLI behavior:

pnpm --dir nested-project exec tsc --noEmit

The CLI command passes.

Workaround

Adding "types": ["node"] fixes the VS Code diagnostic:

{
  "compilerOptions": {
    "typeRoots": ["./node_modules/@types"],
    "types": ["node"]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions