VS Code: “Breakpoint ignored because generated code not found” error

前端 未结 18 2587
无人共我
无人共我 2020-12-13 08:07

I have looked everywhere and I still have issue debugging TypeScript inside VS Code. I have read this thread but still I am not able to hit my breakpoints placed inside a Ty

相关标签:
18条回答
  • 2020-12-13 08:45

    Using Angular I have found that I always point my folder directory to the src folder - that way my work-space is not so cluttered with root files that I never use. But this has given me several problems in the past especially when using VSCode, since many of the functionality seems to me to look at the folder structure, and start from there to run your files. (Expecting some of the missing files)

    So I had this exact same problem with this error message, and learning from past experience I realized that I opened my project one folder deep, instead of the root <app name> folder. So I just closed my project and opened it one folder up (so that all the other files are also included in the folder structure) and my problem was immediately fixed.

    I also believe that many of the above answers about changing your files and folder structure are workarounds to this problem of not opening your work project at the root folder, what ever framework/language you are using.

    0 讨论(0)
  • 2020-12-13 08:46

    if you switch to visual studio type script project you can debug ts files normally i think the issue in app.js.map generation file here is sample from visual studio app.js.map

    {"version":3,"file":"app.js","sourceRoot":"","sources":["app.ts"],"names":["HelloWorld","HelloWorld.constructor"],"mappings":"AAAA;IACIA,oBAAmBA,OAAcA;QAAdC,YAAOA,GAAPA,OAAOA,CAAOA;IAEjCA,CAACA;IACLD,iBAACA;AAADA,CAACA,AAJD,IAIC;AAED,IAAI,KAAK,GAAG,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAAC;AAC/C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC"}

    vs visual studio code app.js.map

    {"version":3,"file":"app.js","sourceRoot":"","sources":["../app.ts"],"names":[],"mappings":"AACA;IACI,oBAAmB,OAAc;QAAd,YAAO,GAAP,OAAO,CAAO;IAEjC,CAAC;IACL,iBAAC;AAAD,CAAC,AAJD,IAIC;AACD,IAAI,KAAK,GAAC,IAAI,UAAU,CAAC,aAAa,CAAC,CAAC;AACxC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AAC3B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC"}

    try to replace it and try again don't forget to consider directory hierarchy of sources

    0 讨论(0)
  • 2020-12-13 08:47

    yes! in my case changing this in launch.json file solve the problem:

      "sourceMapPathOverrides": {
        "webpack:///./~/*": "${webRoot}/node_modules/*",
        "webpack:///./*":   "${webRoot}/*",
        "webpack:///*":     "*",
        "webpack:///src/*": "${webRoot}/*",
      }
    
    0 讨论(0)
  • 2020-12-13 08:49

    I think the problem might be in your 'program' section of launch.json. Try it like this:

    {
        // Name of configuration; appears in the launch configuration drop down menu.
        "name": "Launch",
        // Type of configuration.
        "type": "node",
        "request": "launch",
        // Workspace relative or absolute path to the program.
        "program": "${workspaceRoot}/app.ts",
        // Automatically stop program after launch.
        "stopOnEntry": false,
        // Command line arguments passed to the program.
        "args": [],
        // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
        "cwd": "${workspaceRoot}",
        // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
        "runtimeExecutable": null,
        // Optional arguments passed to the runtime executable.
        "runtimeArgs": ["--nolazy"],
        // Environment variables passed to the program.
        "env": {
            "NODE_ENV": "development"
        },
        // Use JavaScript source maps (if they exist).
        "sourceMaps": true,
        // If JavaScript source maps are enabled, the generated code is expected in this directory.
        "outDir": "${workspaceRoot}"
    }
    
    0 讨论(0)
  • 2020-12-13 08:50

    Facing the same issue and solved it by correcting the path to .ts files.
    My project contains src and dist dirs and the problem was that the generated .map files didn't have the correct path to the src dir.

    The fix - tsconfig.json:

    {
        "compilerOptions": {
            "target": "es5",
            "module": "commonjs",
            "sourceMap": true,
            "outDir": "dist",
            "sourceRoot": "../src"
        }
    }
    

    Initially, my sourceRoot was pointing to src and there is no src dir inside dist.

    Also, sourceMaps should be set to true inside launch.json.

    0 讨论(0)
  • 2020-12-13 08:52

    Facing the same issue and solved it by correcting "webRoot" config in launch.json. Here's my workspace's explorer view.

    Since the compiling result main.js and main.js.map are in "./project/www/build" directory, I change the "webRoot" entry to "${workspaceRoot}/project/www/build" from "${workspaceRoot}", and it worked!

    The launch.json file is as follow:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "Launch Chrome against localhost",
                "type": "chrome",
                "request": "launch",
                "url": "http://localhost:8100",
                "sourceMaps": true,
                "webRoot": "${workspaceRoot}/project/www/build"
            },
            {
                "name": "Attach to Chrome",
                "type": "chrome",
                "request": "attach",
                "port": 9222,
                "url": "http://localhost:8100",
                "sourceMaps": true,
                "webRoot": "${workspaceRoot}/project/www/build"
            }
        ]
    }
    
    0 讨论(0)
提交回复
热议问题