API package validation fails due to ambient type definitions in parent directories
@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
- Clone
vscode-python-environmentson a machine where any@typespackages exist in an enclosing parent directory (such as in~/.node_modules/@typesorC:\Users\<username>\node_modules\@types). - Navigate to the
apipackage:cd api - 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.cjsassumestypescriptis installed atapi/node_modules/typescript/bin/tsc, which throwsMODULE_NOT_FOUNDwhen dependencies are resolved from the repository root.api/package.jsonlacks a"test"script, causing standardnpm testinvocations to fail withnpm 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
- Isolate Consumer
tsconfigs: In bothapi/test/tsconfig.modern.jsonandapi/test/tsconfig.legacy.json, specify:
This prevents TypeScript from ascending out of the temporary test root to discover ambient"types": ["node", "vscode"], "typeRoots": ["../node_modules/@types"]@types/*packages on the host system. - Dynamic
tscResolution: Inapi/scripts/test-package.cjs, resolvetypescript/bin/tscvia:
This allows resolution from either localconst packageRequire = createRequire(path.join(packageRoot, 'package.json')); const typescriptCli = packageRequire.resolve('typescript/bin/tsc');api/node_modulesor rootnode_modules. - Add Lifecycle Script: Add
"test": "npm run test:package"inapi/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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di microsoft/vscode-python-environments
-
microsoft/vscode-python-environments#1796 · 1 assegnatario ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
triage-needed
microsoft/vscode-python-environments#1791 · 1 reazione · 2 assegnatari ·
-
triage-needed
Difficoltà 4/5 3-5 giorni Idoneità per principianti 74/100
microsoft/vscode-python-environments#1779 · 1 commento · 1 reazione ·
-
triage-needed
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
microsoft/vscode-python-environments#1778 · 2 commenti · 1 reazione ·
Tutte le issue di microsoft/vscode-python-environments
Issue simili
-
Type/Bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
OpenNSW/nsw-srilanka#497 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
0xMiden/bridge-portal#132 ·
-
react-doctor severity:warning tech-debt
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
digidem/comapeo-cloud-app#403 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100