Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docker-TypeScript] Using ts-node and nodemon doesn't properly #187

Closed
umarov opened this issue Jan 25, 2019 · 7 comments
Closed

[Docker-TypeScript] Using ts-node and nodemon doesn't properly #187

umarov opened this issue Jan 25, 2019 · 7 comments

Comments

@umarov
Copy link

umarov commented Jan 25, 2019

I have an example project here.

My nodemon command with ts-node looks like this inside nodemon-debug.json:

node --inspect=0.0.0.0:9229 --nolazy -r ts-node/register -r tsconfig-paths/register src/main.ts

The debug command that gets executed by docker is this:

nodemon --config nodemon-debug.json

Dockerfile looks like this:

FROM node:10-alpine

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

COPY ["package.json", "yarn.lock", "npm-shrinkwrap.json*", "./"]

RUN yarn install --silent && mv node_modules ../

COPY . .

EXPOSE 9229
EXPOSE 3000

RUN chmod u+x ./scripts/start.sh

CMD ./scripts/start.sh

launch.json looks like this:

{
  "type": "node",
  "request": "attach",
  "name": "Attach to Docker",
  "port": 9229,
  "address": "0.0.0.0",
  "restart": true,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/usr/src/app",
  "skipFiles": [
    "<node_internals>/**/*.js",
  ]
}

VS Code attaches, but when I put a breakpoint, it looks like this:
image
image

I tried to follow the TypeScript Docker guide as closely as possible. My setup is a bit different. I was wondering if it would be possible to add an example that uses nodemon and ts-node the way I am using it. Or tips on getting it to work. I could make a PR to add directions if I can get this to work.

The nodemon script I use it generated from Nest.js. I change the inspect from --inspect-brk to --inspect=0.0.0.0:9229.

@umarov
Copy link
Author

umarov commented Jan 25, 2019

Setting breakpoints and stepping through code works fine in Google Chrome.

image

I pick the sm (source mapped) version and it works like expected. It doesn't work the same way in VS Code. When I have both Chrome and VS Code connected at the same time. VS Code gets triggered by the same breakpoint I set in Chrome. But the file that's shown is the read-only source map version. Breakpoints work fine on that version in VS Code too, but on the original .ts file the breakpoints don't stick.

@cschroeter
Copy link

cschroeter commented Jan 31, 2019

@auchenberg @umarov
So I am pretty sure that this is a bug in VSCode. You can use ts-node if your local root and the remote root are the same.

{
   "type": "node",
   "request": "attach",
   "name": "Attach to Docker",
   "localRoot": "${workspaceFolder}",
   "remoteRoot": "${workspaceFolder}"
}
FROM node:11.8.0

# This needs to be the same path as on your computer
WORKDIR /Users/cschroeter/my-app

COPY package.json yarn.lock ./
RUN yarn && yarn cache clean

COPY . .

EXPOSE 3000 9229

CMD yarn start
version: '3.7'
services:
  app:
    build: .
    command: yarn start:debug
    volumes:
      - './src:/Users/cschroeter/my-app/src'
    ports:
      - '3000:3000'
      - '9229:9229'

@eddiemonge
Copy link

I have the same issue. You can also take nodemon out of the equation to simplify

@eddiemonge
Copy link

You can use ts-node if your local root and the remote root are the same.

Yes this. Matching the local and remote roots and changing the workdir in docker fixed it but that is not a good fix. not portable at all.

@eddiemonge
Copy link

The sourceMapPathOverrides option fixes it for me:

launch.json

    {
      "type": "node",
      "request": "attach",
      "name": "Docker: Attach to Node",
      "sourceMapPathOverrides": {
        "/usr/app/*": "${workspaceRoot}/*"
      }
    },

Dockerfile

WORKDIR /usr/app

@kristof-mattei
Copy link

This is still an issue.

While the debugger can attach, the location on which the breakpoints are set is wrong:

image

This after setting the right kind of sourceMapPathOverrides.

@connor4312
Copy link
Member

We no longer have a Docker-TypeScript recipe as it has been supplanted by Remote-Containers functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants