API package validation fails due to ambient type definitions in parent directories

Abierto
#1,799 0 comentarios 0 reacciones 1 asignado Ver en GitHub

@DonJayamanne ya está trabajando en esto.

Desde el 19/9/2026.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

Environment data

  • Python Environments extension version: 1.37.0 (@vscode/python-environments@1.4.0)
  • Python extension (ms-python.python) version: N/A (Build / Packaging validation)
  • VS Code version (Help → About): 1.99.0+
  • OS and version: Windows 11 (Reproducible on any OS with ambient parent @types)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.10.0
  • Environment manager in use: N/A
  • Shell: pwsh / cmd / bash
  • Remote / container scenario: none
  • Workspace type: mono-repo
  • Is this a regression?: Yes, introduced in #1793 (build: share API declarations across module formats)

Repro Steps

  1. Clone vscode-python-environments on a machine where any @types packages exist in an enclosing parent directory (such as in ~/.node_modules/@types or C:\Users\<username>\node_modules\@types).
  2. Navigate to the api package:
    cd api
    
  3. Run the API package validation test script:
    npm run test:package
    

Expected behavior

The package test runner (api/scripts/test-package.cjs) creates temporary consumer fixture projects (modern and legacy) in os.tmpdir() and verifies type checking against @vscode/python-environments in complete isolation, referencing only the explicitly installed consumer types (@types/node and @types/vscode).

Actual behavior

TypeScript compilation (tsc --project <consumerRoot>/tsconfig.json) fails during fixture verification because api/test/tsconfig.modern.json and api/test/tsconfig.legacy.json omit types and typeRoots.

Under TypeScript's default type discovery, tsc searches for ambient node_modules/@types folders up the directory hierarchy from the temporary folder through the user home directory. Any broken, partially installed, or incompatible global type definition packages (such as an empty or malformed @types/d3-scale) are implicitly loaded and cause the test suite to abort.

Additionally:

  • api/scripts/test-package.cjs assumes typescript is installed at api/node_modules/typescript/bin/tsc, which throws MODULE_NOT_FOUND when dependencies are resolved from the repository root.
  • api/package.json lacks a "test" script, causing standard npm test invocations to fail with npm error Missing script: "test".

Logs

error TS2688: Cannot find type definition file for 'd3-scale'.
  The file is in the program because:
    Entry point for implicit type library 'd3-scale'
node:child_process:922
    throw err;
    ^

Error: Command failed: C:\Program Files\nodejs\node.exe D:\vscode-python-environments\api\node_modules\typescript\bin\tsc --project C:\Users\Satyam\AppData\Local\Temp\python-environments-api-I2BCwo\modern\tsconfig.json
    at genericNodeError (node:internal/errors:983:15)
    at wrappedFn (node:internal/errors:537:14)
    at checkExecSyncError (node:child_process:883:11)
    at execFileSync (node:child_process:919:15)
    at runNodeScript (D:\vscode-python-environments\api\scripts\test-package.cjs:20:12)
    at Object.<anonymous> (D:\vscode-python-environments\api\scripts\test-package.cjs:77:9)
    at Module._compile (node:internal/modules/cjs/loader:1730:14)
    at Object..js (node:internal/modules/cjs/loader:1895:10)
    at Module.load (node:internal/modules/cjs/loader:1465:32)
    at Function._load (node:internal/modules/cjs/loader:1282:12) {
  status: 2,
  signal: null,
  output: [ null, null, null ],
  pid: 19372,
  stdout: null,
  stderr: null
}

Node.js v22.17.0

Additional context

Resolution
  1. Isolate Consumer tsconfigs: In both api/test/tsconfig.modern.json and api/test/tsconfig.legacy.json, specify:
    "types": ["node", "vscode"],
    "typeRoots": ["../node_modules/@types"]
    
    This prevents TypeScript from ascending out of the temporary test root to discover ambient @types/* packages on the host system.
  2. Dynamic tsc Resolution: In api/scripts/test-package.cjs, resolve typescript/bin/tsc via:
    const packageRequire = createRequire(path.join(packageRoot, 'package.json'));
    const typescriptCli = packageRequire.resolve('typescript/bin/tsc');
    
    This allows resolution from either local api/node_modules or root node_modules.
  3. Add Lifecycle Script: Add "test": "npm run test:package" in api/package.json.
Lenguaje dominante
TypeScript
Estrellas
140
Forks
63
Merge medio
1 d 4 h
PR fusionados (30 d)
35

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/vscode-python-environments

Todos los issues de microsoft/vscode-python-environments

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.