<p>I am trying to figure out if it is possible to use Cloud Code in VSCode to debug a TypeScript Node application in Kubernetes remotely?</p>
<p>I used Cloud Code regularly to debug JS Node applications in Kubernetes, but I am having hard time to configure launch.json to do the same for TypeScript Node app. Sources for that is non-existent and at this point I am not even sure if this is possible.</p>
<p>Here is the launch.json file I configured. Also you can see a setting for local debugging which works fine:</p>
<pre><code>{
&quot;configurations&quot;: [
    {
        &quot;name&quot;: &quot;Kubernetes: Run/Debug&quot;,
        &quot;type&quot;: &quot;cloudcode.kubernetes&quot;,
        &quot;request&quot;: &quot;launch&quot;,
        &quot;skaffoldConfig&quot;: &quot;${workspaceFolder}\\skaffold.yaml&quot;,
        &quot;watch&quot;: false,
        &quot;cleanUp&quot;: false,
        &quot;portForward&quot;: true,
        &quot;imageRegistry&quot;: &quot;zzz.common.repositories.zzz.zzz&quot;
    },
    {
        &quot;type&quot;: &quot;node&quot;,
        &quot;request&quot;: &quot;launch&quot;,
        &quot;name&quot;: &quot;Local Debug&quot;,
        &quot;runtimeExecutable&quot;: &quot;node&quot;,
        &quot;runtimeArgs&quot;: [&quot;--nolazy&quot;, &quot;-r&quot;, &quot;ts-node/register/transpile-only&quot;],
        &quot;args&quot;: [&quot;${workspaceRoot}/lcs/src/index.ts&quot;],
        &quot;cwd&quot;: &quot;${workspaceRoot}/lcs&quot;,
        &quot;internalConsoleOptions&quot;: &quot;openOnSessionStart&quot;,
        &quot;env&quot;: { &quot;NODE_ENV&quot;: &quot;development&quot; },
        &quot;skipFiles&quot;: [&quot;&lt;node_internals&gt;/**&quot;, &quot;node_modules/**&quot;]
      }
]}
</code></pre>
<p>In my tsconfig.json I have &quot;sourceMap&quot;: true. I assume I need to map my dist folder in Kubernetes (that is where I compile TS files to JS files) to src folder (which contains original TS files). Problem is I couldn't find any documentation to do that.</p>
<p>Here is my docker file so you can see that I am putting the compiled files into ./dist folder:</p>
<pre><code>FROM node:19-alpine as builder
WORKDIR /app
COPY package*.json ./
COPY tsconfig.json ./
RUN npm install
COPY . .
RUN npm run build


FROM node:19-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY --from=builder /app/dist ./dist

EXPOSE 3000
CMD [ &quot;node&quot;, &quot;./dist/index.js&quot; ]
</code></pre>

<p>I figured it out. It needed a bit more configuration in launch.json. Specifically debug section with sourceFileMap. Here is the final result if anybody else has trouble making it work:</p>
<pre><code>{
    &quot;configurations&quot;: [
        {
            &quot;name&quot;: &quot;Kubernetes: Run/Debug&quot;,
            &quot;type&quot;: &quot;cloudcode.kubernetes&quot;,
            &quot;request&quot;: &quot;launch&quot;,
            &quot;skaffoldConfig&quot;: &quot;${workspaceFolder}\\skaffold.yaml&quot;,
            &quot;watch&quot;: false,
            &quot;cleanUp&quot;: false,
            &quot;portForward&quot;: true,
            &quot;imageRegistry&quot;: &quot;zzz.common.repositories.zzz.zzz&quot;,
            &quot;debug&quot;: [
                {
                    &quot;image&quot;: &quot;zzz.common.repositories.zzz.zzz/zzz-lcs/k8s&quot;,
                    &quot;containerName&quot;: &quot;lcs&quot;,
                    &quot;sourceFileMap&quot;: {
                        &quot;${workspaceFolder}\\lcs\\dist&quot;: &quot;/app/dist&quot;
                    }
                }
            ]
        },
        {
            &quot;type&quot;: &quot;node&quot;,
            &quot;request&quot;: &quot;launch&quot;,
            &quot;name&quot;: &quot;Local Debug&quot;,
            &quot;runtimeExecutable&quot;: &quot;node&quot;,
            &quot;runtimeArgs&quot;: [&quot;--nolazy&quot;, &quot;-r&quot;, &quot;ts-node/register/transpile-only&quot;],
            &quot;args&quot;: [&quot;${workspaceRoot}/lcs/src/index.ts&quot;],
            &quot;cwd&quot;: &quot;${workspaceRoot}/lcs&quot;,
            &quot;internalConsoleOptions&quot;: &quot;openOnSessionStart&quot;,
            &quot;env&quot;: { &quot;NODE_ENV&quot;: &quot;development&quot; },
            &quot;skipFiles&quot;: [&quot;&lt;node_internals&gt;/**&quot;, &quot;node_modules/**&quot;]
          }
    ]
}
</code></pre>
<p>Note that my files are located in my local inside /lcs/app/src and my build put them in ./lcs/dist</p>
