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

Aperta
#1,799 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@DonJayamanne ci sta già lavorando.

Dal 19/9/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

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.
Lingua principale
TypeScript
Stelle
140
Fork
63
Merge medio
1g 4h
PR unite (30g)
35

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/vscode-python-environments

Tutte le issue di microsoft/vscode-python-environments

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.