typescript debugging with npm link

28 views Asked by At

I'm wanting to do something that feels like it should be rather basic (getting breakpoints to work properly so I can use them on the code I'm working on and on my own npm linked module).

I have npm linked my first module into the second one. Both modules have a basic src and dist folder approach to keep things simple

Both have similar tsconfig.json that creates source maps. I've tried inline, I've tried sourcemaps that have the typescript embedded, I've tried all sorts of things, but no matter what I try if I put a break point in on the .ts files in the modules/@myorg/firstmodule folder the most I can ever get is for it to break in the .js file.

I've tried many different things with package.json, tsconfig, the launch config, using ts-node, tsx, and just plain tsc with node, etc. None of it really works properly.

Here's a snippet from package.json in the firstmodule that is npm linked into the other one. I was setting breakpoints on code that is originally under something like ./src/config/config.ts and added the files array in thinking maybe it needed that in dist to pickup the mapping files over to these subfolders, but that didn't work, and so I'm kind of at a loss.

package.json

"main": "./dist/index.js",
  "types": "./dist/index.d.ts",
  "typings": "./dist/index.d.ts",
  "files": [
    "./dist/**/*"
  ],

*I left the visual-studio-code tag because it may be specific to that app, everything I've tried so far has been in that app, and I'm not familiar enough with other editors to try config in something else.

All I can say is that vs-code as an editor seems to trace the code just fine.

Other code I have that should in theory make this work

tsconfig.json

{
  "include": ["./src/**/*"],
  "compilerOptions": {    
    /* Visit https://aka.ms/tsconfig to read more about this file */
    /* Projects */
    "composite": true,                                  /* Enable constraints that allow a TypeScript project to be used with project references. */
    /* Language and Environment */
    "target": "ESNext",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    /* Modules */
    "module": "CommonJS",                                  /* Specify what module code is generated. */    
    "sourceRoot": "",
    "rootDir": "src",                                   /* Specify the root folder within your source files. */
    "outDir": "dist",                                   /* Specify an output folder for all emitted files. */
    //"moduleResolution": "node",                          /* Specify how TypeScript looks up a file from a given module specifier. */     
    /* Emit */        
    //"inlineSourceMap": true,
    "sourceMap": true,
    "inlineSources": true,
    "declaration": true,                                 /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
    "declarationMap": true,
    "declarationDir": "dist",
    /* Interop Constraints */
    "allowSyntheticDefaultImports": true,                /* Allow 'import x from y' when a module doesn't have a default export. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "forceConsistentCasingInFileNames": true,            /* Ensure that casing is correct in imports. */
    /* Type Checking */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "alwaysStrict": true,                                /* Ensure 'use strict' is always emitted. */
  }
}

launch.json

{
      "name": "tsc",
      "type": "node",
      "request": "launch",
      "runtimeArgs": ["--preserve-symlinks"],
      "program": "${workspaceFolder}/src/tests.ts",
      "preLaunchTask": "tsc: build - tsconfig.json",
      "sourceMaps": true,
      "resolveSourceMapLocations": [
        "${workspaceFolder}/**/*",
        "${workspaceFolder}/node_modules/@korodarn/amp/dist/**/*"
      ]      
  }
0

There are 0 answers