microsoft / microsoft/vscode

The built-in npm support extension errors and causes launch delay when encountering certain .modules.yaml

Open
#328,668 0 comments 0 reactions 1 assignee Claimed by @meganrogge View on GitHub
confirmation-pending tasks
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Type: Bug

It seems the built-in npm extension tries to read the non-standard "node_modules/.modules.yaml" file, and when it doesn't find what it looks for, it throws error, and causes the preLaunchTask to not run immediately.

### Steps to reproduce:

1. I made a minimum reproducible setup in the zip: [npm extension issue.zip](https://github.com/user-attachments/files/30649886/npm.extension.issue.zip). But in case you can't download/open it or it expires, here is the written version:

Written version

Create a `.code-workspace` file, with content:
```json
{
"folders": [
{
"path": "."
},
],
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"args": ["--help"],
"preLaunchTask": "Pre",
},
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"label": "Pre",
"type": "shell",
"command": "echo",
"args": ["Hello World"],
},
]
},
}
```
Create `package.json` with content
```json
{
"scripts": {
"hello": "world"
}
}
```
Create a `node_modules` directory in the same directory. Inside, create a `.modules.yaml` file with content
```json
{}
```

2. Open the `.code-workspace` file with freshly installed VSCode.
3. In Command Palette, execute `Explorer: Focus on NPM Scripts View`. The NPM Scripts panel should appear in the sidebar. Inside we should see the script `hello: world`. Instead it is empty.
4. Press F5 to start debugging. Notice it takes 3-4 seconds before the "Pre" task to execute. Open the Developer Tools to find these errors:
```
mainThreadExtensionService.ts:79 [vscode.npm]Cannot read properties of undefined (reading '0')
$onExtensionRuntimeError @ mainThreadExtensionService.ts:79
mainThreadExtensionService.ts:80 TypeError: Cannot read properties of undefined (reading '0')
at Lp (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:45:1579)
at Ws.exports (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:45:1463)
at async uu (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:12289)
at async bn (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:14575)
at async Ir (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:14350)
at async wn (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:17196)
at async Ht (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:17529)
at async gu (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:16631)
at async cu (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:15924)
at async vn.provideTasks (d:\vscode\1.131.0\e4c7e7b1d6\resources\app\extensions\npm\dist\npmMain.js:55:13220)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:80
ERR An unknown error occurred. Please consult the log for more details.
```
5. At this point, there are 3 ways to workaround the issue. Doing either one will bring the NPM Scripts panel back and remove the delay:
1) Change setting `"npm.autoDetect": "off"`.
2) Disable the npm extension.
3) Change the content of `.modules.yaml` to `{ "packageManager": "whatever" }`.

It seems the extension locks some mutex, looks for the `packageManager` key, not finding it, give up but not release the lock until some timeout after 3-4 seconds happens, then the task workflow is allowed to continue.

Isn't `.modules.yaml` a pnpm specific implementation detail? I think VSCode is wrong to depend on it, since pnpm can change its structure at any time without obligation to tell anyone outside.

VS Code version: Code 1.131.0 (e4c7e7b1d6d060162f4aa7f8225271b67ce1df75, 2026-07-28T10:51:25Z)
OS version: Windows_NT x64 10.0.26200
Modes: Unsupported

System Info

|Item|Value|
|---|---|
|CPUs|AMD Ryzen 7 5800X 8-Core Processor (16 x 3800)|
|GPU Status|2d_canvas: enabled
GPU0: VENDOR= 0x10de, DEVICE=0x1e84 [NVIDIA GeForce RTX 2070 SUPER], DRIVER_VENDOR=NVIDIA, DRIVER_VERSION=32.0.16.1074 *ACTIVE*
GPU1: VENDOR= 0x1414, DEVICE=0x008c [Microsoft Basic Render Driver], DRIVER_VERSION=10.0.26100.8875
Machine model name:
Machine model version:
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
trees_in_viz: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgpu: enabled
webnn: disabled_off|
|Load (avg)|undefined|
|Memory (System)|15.92GB (8.01GB free)|
|Process Argv||
|Screen Reader|no|
|VM|0%|

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.