I'm using webpack-dev-server
to run an Nestjs application inside a Docker container. All is up and running, but I can't debug the application from my VS Code instance. I'm trying to expose the 9229 port using this configuration on the webpack.config.js
:
devServer: {
host: '0.0.0.0',
port: 9229,
},
When I run netstat -l
inside the container I can see that node is not listening the 9229 port:
I'm exposing the port 9229 in the Dockerfile and docker-compose files. The Dockerfile:
FROM node:12.16.1-alpine
WORKDIR /usr/src/app
COPY package.json yarn.lock ./
RUN yarn
COPY . .
EXPOSE 3000
EXPOSE 9229
CMD [ "yarn", "run", "start:debug"]
And the docker-compose.yml file:
version: '3.7'
services:
open-tuna-api:
image: opentunaapi
ports:
- 3000:3000
- 9229:9229
volumes:
- ./dist:/usr/src/app/dist
- ./:/usr/src/app
networks:
- open-tuna-network
expose:
- 9229
networks:
open-tuna-network:
And this is the script I'm using to run the application:
"start:debug": "webpack --config webpack.config.js && node --inspect=0.0.0.0:9229 node_modules/webpack-dev-server/bin/webpack-dev-server.js",
My launch configuration is as follow:
{
"name": "Attach",
"preLaunchTask": "compose-up",
"stopOnEntry": true,
"type": "node",
"request": "attach",
"port": 9229,
"cwd": "${workspaceFolder}", // the root where everything is based on
"localRoot": "${workspaceFolder}", // root of all server files
"remoteRoot": "/usr/src/app", // workspace path which was set in the dockerfile
"outFiles": ["${workspaceFolder}/dist/**/*.js"], // all compiled JavaScript files
"protocol": "inspector",
"restart": true,
"sourceMaps": true,
"trace": "verbose",
"address": "0.0.0.0",
"skipFiles": [
"<node_internals>/**"
],
}
And when I run this configuration with the container up and running I'm receiving a message saying that VS Code cannot connect to the process.
So, my question is: is there a way to debug JavaScript / TypeScript app running on webpack-dev-server
inside a Docker container? What is wrong in my environment?
Thanks for the help.
EDIT
Apparently my issue has no relation with Docker, since I can reproduce it outside of the container.
Have a look at your config and make sure you include the program
field. And point it to the right file under node_modules
.
"program": "${workspaceRoot}/node_modules/webpack-dev-server/bin/webpack-dev-server.js"
That should get you going.
If you want more insight into this, there's a longer conversation that you might find useful - check out this comment on the main webpack-dev-server GitHub repo.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.