angular-electron icon indicating copy to clipboard operation
angular-electron copied to clipboard

Can not find sourcemaps while debugging in VSCode

Open herrKlein opened this issue 9 years ago • 8 comments

I managed to connect from VSCode to the electron app, using this launch.config:

{ "name": "Debug", "type": "chrome", "request": "launch", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", "runtimeArgs": [ "${workspaceRoot}/dist", "--enable-logging", "--remote-debugging-port=9222" ], "sourceMaps": true, "webRoot": "${workspaceRoot}/dist" }

But I can't set any breakpoinst cause sourcemaps are not found. I tried to include this line

"sourceMapPathOverrides": { "webpack:///./*": "${webRoot}/*" }

from the Angular CLI launch.json file, but to no avail. Is there anyone who got this to work ?

herrKlein avatar Nov 23 '17 11:11 herrKlein

I would be happy, if someone could help us.

feco93 avatar Dec 12 '17 15:12 feco93

I would also love to know how to debug from VSCode!

dylandepass avatar Dec 28 '17 05:12 dylandepass

Here is what I did to debug from VSCode and Chrome Developer Tools:

  1. Sourcemaps for the main process: Add --sourceMap true to the "build:electron:main" script in package.json to create sourcemaps for main.ts when build the electron application. Full script: "build:electron:main": "tsc main.ts --outDir dist --sourceMap true && copyfiles package.json dist && cd dist && npm install --prod && cd ..",

  2. Sourcemaps for the renderer process: Delete the flowing lines in webpack.config.js to create sourcemaps for all Angular code:

  // plugins.push(new SourceMapDevToolPlugin({
  //   "filename": "[file].map[query]",
  //   "moduleFilenameTemplate": "[resource-path]",
  //   "fallbackModuleFilenameTemplate": "[resource-path]?[hash]",
  //   "sourceRoot": "webpack:///"
  // }));
  1. Create a configuration in the launch.json to run the Electron application in debug mode:
{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Electron: Main",
            "program": "${workspaceFolder}\\main.ts",
            "outFiles": [
                "${workspaceRoot}/dist/main.js"
            ],
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "runtimeArgs": [
                "--remote-debugging-port=9223",
                "./dist"
            ]
        },
    ]
}
  1. Start debuging with above configuration in Visual Studio Code. I can set breakpoints in main.ts now. But to debug the Angular code, I need to open the Chome Developer Tools and set breakpoints.

Summary:

  • Debug the main process code in Visual Studio Code
  • Debug the render process code in Chrome Developer Tools

I try to config to debug all Angular code in Visual Studio Code but not success.

If anyone want to help, here is my full configurations in the launch.json:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Electron: Main",
            "program": "${workspaceFolder}\\main.ts",
            "outFiles": [
                "${workspaceRoot}/dist/main.js"
            ],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "windows": {
                "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
            },
            "runtimeArgs": [
                "--remote-debugging-port=9223",
                "./dist"
            ]
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "attach",
            "port": 9223,
            "webRoot": "${workspaceRoot}/dist",
            "timeout": 30000
        },
    ],
    "compounds": [
        {
            "name": "Electron: All",
            "configurations": [
                "Electron: Main",
                "Electron: Renderer"
            ]
        }
    ]
}

But now I need to start debugging with "Electron: All" configuration.

nccnm avatar Jan 13 '18 10:01 nccnm

Try this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Electron: Main",
            "program": "${workspaceFolder}\\main.ts",
            "outFiles": [
                "${workspaceRoot}/dist/main.js"
            ],
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "windows": {
                "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
            },
            "runtimeArgs": [
                "--remote-debugging-port=9223",
                "./dist"
            ]
        },
        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "launch",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "windows": {
              "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
            },
            "runtimeArgs": [
              "${workspaceRoot}/dist/main.js",
              "--remote-debugging-port=9222"
            ],
            "webRoot": "${workspaceRoot}"
          },
    ]
}

shalomdotnet avatar Jan 14 '18 16:01 shalomdotnet

I figure out how to debug the render process and the entire Angular project, follow the steps from the @nccnm comment from 1 to 2 and for step 3 you must use the following config in your launch.json:

{
   "name": "Electron: Renderer",
   "type": "chrome",
   "request": "launch",
   "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
   "windows": {
         "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
   },
   "runtimeArgs": [
         "${workspaceRoot}/dist/main.js",
         "--remote-debugging-port=9222"
   ],
   "timeout": 30000,
   //"preLaunchTask": "npmStart",
   "webRoot": "${workspaceRoot}"
}

Also you need to modify the script for electron in the package.json file like this:

"electron:serve": "npm run build:electron:main && electron ./dist --serve --remote-debugging-port=9222"

Also don't forget to disable the dev tools in main.ts comment the line with the code win.webContents.openDevTools();

With this you can execute using npm start and then start the debugger, or you can use the preLaunchTask and create a tasks.json for run the project before the debugger.

darkyelox avatar Jan 18 '18 18:01 darkyelox

This config helps me:

        {
            "name": "Electron: Renderer",
            "type": "chrome",
            "request": "launch",
            "cwd": "${workspaceRoot}",
            "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
            "windows": {
                  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
            },
            "runtimeArgs": [
                "--remote-debugging-port=9222",
                ".",
            ],
            "sourceMapPathOverrides": {
                "webpack:\\*": "${workspaceRoot}/*"
            },
            "sourceMaps": true,
            "timeout": 30000,
            //"preLaunchTask": "npmStart",
            "webRoot": "${workspaceRoot}/dist"
         }        

dmitriyse avatar Apr 13 '18 16:04 dmitriyse

Not working now.

adrimarti avatar Nov 05 '18 22:11 adrimarti

Spent hours today, finally got the launch debugger working for the main process.

{
			"type": "node",
			"request": "launch",
			"name": "Electron Main",
			"program": "${workspaceFolder}/main.ts",
			"outFiles": [
				"${workspaceRoot}/main.js",
			],
			"cwd": "${workspaceRoot}",
			"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
			"windows": {
				"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
			},
			"args": ["--serve"],
			"runtimeArgs": [
				".",
			],
			"outputCapture": "std",
			"preLaunchTask": "npm: electron:serve-tsc",
		},

Keep in mind my main.ts file outputs main.js in the same top level directory. And more importantly, you need to have the ng serve running ahead of time because this is not running off of the dist folder. Its serving from the devkit server. Hope this helps

nikhilnxvverma1 avatar May 11 '19 18:05 nikhilnxvverma1