I cannot get remote debugging up & running for my NodeJS Azure function in a docker container.
Setup:
I followed the tutorial from documentation and created a sample HTTP triggered function
func init --worker-runtime node --language typescript --docker
func new --name HttpExample --template "HTTP trigger" --authlevel anonymous
It created the following folder structure
And the generated docker file
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 started the container with the turned-on Node debugger
docker run -p 8080:80 -p 9233:9233 -e NODE_OPTIONS=--inspect=0.0.0.0:9233 -it af-docker
From the container output, I can see that the debugger is 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
So I edited the launch.json
file to add support for remote debugging
{
"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,
}
]
}
Result:
When I run the debugger (F5
), I can see from the container output that the debugger is attached
info: Host.Function.Console[0]
Debugger attached.
However, I get the following error in the debug console and breakpoints are not hit/binded
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'
Both paths are invalid (C:\azure-functions-host\**
) and (C:\home\site\**
) and do not exist on the local machine. I suppose there is some misconfiguration in the launch.json
file, but I cannot figure out what is wrong.
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'
You are getting this error because debugger is trying to look for dist\src\functions
folder in your folder structure.
To generate dist
folder, run the commands in the following order-
1. func init --worker-runtime node --language typescript --docker
2. func new --name HttpExample --template "HTTP trigger" --authlevel anonymous
3. npm install
4. npm start
You will be able to see below folder structure.
Then I made the same changes which you did in launch.json
file.
{
"version": "0.2.0",
"configurations": [
{
"name": "Docker: Attach to Node",
"type": "node",
"request": "attach",
"remoteRoot": "/site/wwwroot/dist/src/functions",
"localRoot": "${workspaceRoot}\\src\\functions",
"port": 9233,
"address": "localhost",
"sourceMaps": true,
}
]
}
I started the debugger and got the expected output.