I am facing issues setting up remote debugging for my NodeJS Azure function in a docker container.
Configuration:
Following the guidelines from official documentation, I created an HTTP triggered function as per the steps below:
func init --worker-runtime node --language typescript --docker
func new --name HttpExample --template "HTTP trigger" --authlevel anonymous
This resulted in the creation of the specified folder structure and Docker file.
https://i.sstatic.net/wkLsx.png
The Docker file generated was as follows:
FROM mcr.microsoft.com/azure-functions/node:4-node18
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
COPY . /home/site/wwwroot
RUN cd /home/site/wwwroot && \
npm install && \
npm run build
I initiated the container with Node debugger enabled using the command below:
docker run -p 8080:80 -p 9233:9233 -e NODE_OPTIONS=--inspect=0.0.0.0:9233 -it af-docker
Subsequently, I found that the debugger was indeed listening on port 9233
.
info: Host.Function.Console[0]
Debugger listening on ws://0.0.0.0:9233/77214a10-aeb3-47e0-ac5a-2dcd4f021008
info: Host.Function.Console[0]
For help, see: https://nodejs.org/en/docs/inspector
To enable remote debugging, I edited the launch.json
file with appropriate configurations:
{
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Docker: Attach to Node",
"remoteRoot": "/site/wwwroot/dist/src/functions",
"localRoot": "${workspaceRoot}\\src\\functions",
"port": 9233,
"address": "localhost",
"sourceMaps": true,
}
]
}
Outcome:
Upon initiating debugging (F5
), the container output indicated successful attachment of the debugger.
info: Host.Function.Console[0]
Debugger attached.
However, despite this success message, I encountered errors in the debug console suggesting issues with source map paths and breakpoints not functioning correctly.
LanguageWorkerConsoleLogWorker b62c4a73-8509-4a3f-a496-cca18cb56bb0 connecting on 127.0.0.1:42681
worker-bundle.js:2
Could not read source map for file:///azure-functions-host/workers/node/dist/src/nodejsWorker.js: ENOENT: no such file or directory, open 'C:\azure-functions-host\workers\node\dist\src\nodejsWorker.js.map'
Could not read source map for file:///home/site/wwwroot/dist/src/functions/HttpExample.js: ENOENT: no such file or directory, open 'C:\home\site\wwwroot\dist\src\functions\HttpExample.js.map'
The invalid paths (C:\azure-functions-host\**
) and (C:\home\site\**
) do not exist locally, indicating potential misconfiguration in the launch.json
file. Further investigation is required to rectify this issue.