Repository navigation
Description
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 build: share API declarations across module formats #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.
Activity
fix(api): Isolate API package validation consumers from ambient type …