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

ts is compiled into cjs and mjs suffix files and cannot be debugged using vscode. #200665

Closed
tomgao365 opened this issue Dec 12, 2023 · 2 comments · Fixed by microsoft/vscode-js-debug#1906
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues

Comments

@tomgao365
Copy link

tomgao365 commented Dec 12, 2023

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.85.0
  • OS Version: windows 11 23H2

Steps to Reproduce:

  1. create a project, and run pnpm init
  • package.json
{
  "name": "vscode-debug-esm-cjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "tsup --watch",
    "build": "tsup"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@tomjs/tsconfig": "^1.1.2",
    "@types/node": "^20.10.4",
    "tsup": "^8.0.1",
    "typescript": "^5.3.3"
  }
}
  • src/index.ts
const now = Date.now();
console.log(now);
  • tsup.config.ts
import { defineConfig } from 'tsup';

export default defineConfig({
  entry: ['src/index.ts'],
  format: ['cjs', 'esm'],
  splitting: false,
  sourcemap: true,
  clean: true,
});

.vscode/launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Debug js",
      "type": "node",
      "request": "launch",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/dist/index.js"
    },
    {
      "name": "Debug mjs",
      "type": "node",
      "request": "launch",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/dist/index.mjs"
    },
    {
      "name": "Debug cjs",
      "type": "node",
      "request": "launch",
      "skipFiles": [
        "<node_internals>/**"
      ],
      "program": "${workspaceFolder}/dist/index.cjs"
    }
  ]
}
  1. run pnpm build
  2. Run and Debug , test Debug js and Debug

image

image

Files with the ".mjs" suffix cannot be debugged, but files with the ".js" suffix can be debugged.

image

  1. add "type":"modules" to package.json, and run pnpm build. Files with the "*.cjs" suffix cannot be debugged, the same problem as ".mjs"

  2. The full demo is https://github.com/my-alpha/vscode-debug-esm-cjs

@vscodenpa
Copy link

Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.85.0. Please try upgrading to the latest version and checking whether this issue remains.

Happy Coding!

@roblourens roblourens assigned connor4312 and unassigned roblourens Dec 12, 2023
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Dec 13, 2023
Fixes microsoft/vscode#200665

Requires use of my picomatch fork due to micromatch/picomatch#125.
We could alternatively use brace expansion until that's fixed, but that's much less
efficient that using a logical or.
@connor4312 connor4312 added bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues labels Dec 13, 2023
@connor4312
Copy link
Member

Thanks for the nice issue, you can also work around this by manually specifying the outFiles in your launch.json to include .{js,mjs,cjs} instead of just .js

connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Dec 13, 2023
Fixes microsoft/vscode#200665

Requires use of my picomatch fork due to micromatch/picomatch#125.
We could alternatively use brace expansion until that's fixed, but that's much less
efficient that using a logical or.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 27, 2024
@aiday-mar aiday-mar added this to the December / January 2024 milestone Feb 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug debug Debug viewlet, configurations, breakpoints, adapter issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants