Search code examples
dockerdebuggingvscode-devcontainer

VSCode dev container fails to load ms-vscode.js-debug extension correctly


I am using a node:alpine base image, which I extend with some additional tools that I need. The compose and container run totally fine.

The issue is: When I run any node or npm command in that container. Lets say npm install I get this error message:

node:internal/modules/cjs/loader:1093
  throw err;
  ^

Error: Cannot find module '/root/.vscode-server/data/User/workspaceStorage/57db504abae22291c6f0acc55d5d6d41/ms-vscode.js-debug/bootloader.js'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1090:15)
    at Module._load (node:internal/modules/cjs/loader:934:27)
    at internalRequire (node:internal/modules/cjs/loader:168:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1454:5)
    at loadPreloadModules (node:internal/process/pre_execution:605:5)
    at setupUserModules (node:internal/process/pre_execution:122:3)
    at prepareExecution (node:internal/process/pre_execution:113:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:40:3)
    at node:internal/main/run_main_module:10:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

My devcontainer.json looks like this:

{
  {
    "dockerComposeFile": [
      "./compose.dev.yml"
    ],
    "service": "frontend",
    "shutdownAction": "stopCompose",
    "workspaceFolder": "/workspaces/frontend",
    "customizations": {
    "vscode": {
      "extensions": [
        "aaron-bond.better-comments",
        "streetsidesoftware.code-spell-checker",
        "ms-azuretools.vscode-docker",
        "mikestead.dotenv",
        "GitHub.copilot",
        "mhutchie.git-graph",
        "GraphQL.vscode-graphql",
        "GraphQL.vscode-graphql-syntax",
        "rome.rome",
        "svelte.svelte-vscode",
        "redhat.vscode-yaml"
      ]
    }
  }
}

compose.dev.yml looks like this:

version: "3.9"
services:
  frontend:
    build: .
    volumes:
      - workspace-volume:/workspaces
volumes:
  workspace-volume:

Dockerfile looks like this:

FROM node:alpine
RUN npm install -g npm@latest

RUN apk -U upgrade && apk add git vim zsh curl openssh

RUN sed -i -r 's|bin\/ash|bin\/zsh|g' /etc/passwd

RUN curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh | sh

In the remote server logs I can see that vscode even states, that is has the extension installed sucessfully:

Extension installed successfully: ms-vscode.js-debug

However, as it turns out the installation path seems to be:

/root/.vscode-server/bin/linux-alpine/extensions/ms-vscode.js-debug

At least thats the only folder that I can find, which contains something similar to what is described as missing.

I can disable the auto attach feature from vs code, which prevents this error from happening. However, this only gets rid of a symptom. If I attach manually to any node process for debugging I only get a toast at the bottom right of vscode stating:

Error listing processes: process terminated with exit code: 1

So I only can assume that this seems to be the same error. I did not find any logs that give a more detailed explanation for this error message.

As a sidenote: Doing the same with a debian based image works perfectly fine. So it would be logical to assume that this issue is related to alpine linux.

Does anyone have a solutions for this?


Solution

  • This is a bug in VSCode: https://github.com/microsoft/vscode/issues/137794

    Workaround: "Toggle Auto Attach" to disabled and then back to enabled/smart.