White window when debugging Electron forge "typescript + webpack" app from VSCode - MAIN_WINDOW_WEBPACK_ENTRY variable is not being set - visual-studio-code

I created an Electron forge project as described in the forge guide using the "typescript + webpack" template:
> yarn create electron-app debugging-test --template=typescript-webpack
The generated app works fine when running npm start. Then I wanted to configure VSCode debugger for this template so I followed the debugging section of the forge guide and created launch.json file with this content:
{
"type": "node",
"request": "launch",
"name": "Electron Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-nix",
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron-forge-vscode-win.cmd"
},
// runtimeArgs will be passed directly to your Electron application
"runtimeArgs": [
"foo",
"bar"
],
"cwd": "${workspaceFolder}"
}
This does not really work for me. After clicking F5 the debugger starts but it doesn't break on any breakpoints in the main process nor no window appears. Then I tried the launch.json from Microsoft's vscode-recipes:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Electron: Main",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron",
"runtimeArgs": [
"--remote-debugging-port=9223",
"."
],
"windows": {
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/electron.cmd"
}
},
{
"name": "Electron: Renderer",
"type": "chrome",
"request": "attach",
"port": 9223,
"webRoot": "${workspaceFolder}",
"timeout": 30000
}
],
"compounds": [
{
"name": "Electron: All",
"configurations": [
"Electron: Main",
"Electron: Renderer"
]
}
]
}
This one, after hitting F5, starts the Electron window fine and even breakpoints in the main process are hit but no content is loaded to the window. The window is white. When breaking on line 21 in index.ts:
mainWindow.loadURL(MAIN_WINDOW_WEBPACK_ENTRY);
I see that the MAIN_WINDOW_WEBPACK_ENTRY variable is not set and that's why there is no content loaded to the window.
What's the correct VSCode setup to debug "typescript + webpack" electron's forge template?

I found this is a bug in Windows that is tracked here on Github. The workaround is to remove the fork-ts-checker-webpack-plugin. E.g., in webpack.plugins.js remove the new ForkTsCheckerWebpackPlugin() from the array for now until it is fixed:
//const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
module.exports = [/*new ForkTsCheckerWebpackPlugin()*/];
After that debugging both, main and renderer, processes work great!

Related

VS Code console.log() appears in developer tools instead of debug console

I've been working on a VS Code extension using the Hello World example generated by Yeoman (yo code). The console.log() message only shows up in the Developer Tools, but not in the Debug Console like all of the VS Code documentation suggests. Here is my launch.json (it is unchanged from what yo code generated:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
I've tried adding "console": "internalConsole", "debugOptions": ["RedirectOutput"], and "outputCapture": "std" as suggested in various other answers on Stack Overflow, but A) none of those work and B) they give an error in launch.json that Property <property> is not allowed.
I'm launching using F5 (run with debugging). Breakpoints do work, logpoints don't log anything to Debug Console either.
What am I missing?

How to run flutter in chrome with args in VS Code

How can I run my flutter app in chrome with args?
I want to run/debug/attach my flutter app in a chrome session with --disable-web-security.
In the end I would expect to have a single launch configuration that does launch my app in a single chrome session (similar to flutter run -d chrome).
In the launch.json, I did play around with attach/launch, compounds, tasks but could not make it work.
{
"version": "0.2.0",
"compounds": [
{
"name": "Launch D1",
"configurations": [
"Launch Chrome",
"app1"
],
}
],
"configurations": [
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"webRoot": "${workspaceFolder}/app1",
"runtimeArgs": [
"--disable-web-security",
"--user-data-dir=%APPDATA%\\..\\Local\\tempc"
],
},
{
"name": "app1",
"cwd": "app1",
"request": "launch",
"type": "dart",
"deviceId": "chrome"
}
]
}
If you're having certificate issues running on web, you can disable the warnings using "runtimeArgs": ["--ignore-certificate-errors"]
You can also follow other workarounds mentioned on this GitHub issue thread.

Is it possible to launch a vscode extension with a set of custom settings?

I'm developing a vscode extension, and while testing it out I've hit a bit of a snag. Some functionality depends on custom settings that I define in the configuration of package.json. I would like to be able to launch a new VSCode window with the settings set to particular values, but I can't find how to do that.
What I have in launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"ns.customSetting": "customValue"
},
{
"name": "Extension with another value",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceRoot}"
],
"ns.customSetting": "anotherValue"
}
]
}
That hasn't been working, but hopefully the idea is clear. I want that new window to open with the custom setting already set to the value I want. How do I do that?

VSCode debugger not working in Jest tests

I'm struggling to get the Visual Studio Code debugger working in with Jest tests.
Here is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true
}
]
}
Here are my Jest tests with a couple of breakpoints:
When I hit the green play button to run the tests with the debugger, the breakpoints are never hit.
Any help would be appreciated
Personnally I use this configuration
{
"name": "Launch e2e test",
"type": "node",
"request": "launch",
"env": {
"NODE_ENV": "test"
},
"args": [
"--colors",
"--config=${workspaceFolder}/jest-e2e.config.js",
"--runInBand",
"--coverage"
],
"runtimeArgs": [
"--nolazy"
],
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
},
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart"
}
Change jest-e2e.config.js by your configuration file. And remove or keep coverage
Like Laura Slocum said you will certainly have problem with line number. In my case personnaly think that the problem come from the jest configuration, the transform :
transform: {
"^.+\\.(t|j)s$": "ts-jest"
},
This configuration let's me debug the jest test. Unfortunately hitting a breakpoint in the component does not show the correct line, even though it is stepping through the correct code. I believe this is probably a VSCode error though
{
"name": "Jest", // This is the configuration name you will see in debug sidebar
"type": "node",
"request": "launch",
"port": 5858,
"address": "localhost",
"stopOnEntry": false,
"runtimeExecutable": null,
"env": {
"NODE_ENV": "development"
},
"console": "integratedTerminal",
"preLaunchTask": "compile",
"runtimeArgs": [
"--inspect-brk", // node v8 use debug-brk if older version of node
"${workspaceRoot}/node_modules/.bin/jest",
"--watch",
"--bail",
"--runInBand"
],
"cwd": "${workspaceRoot}"
},
I had the same problem with line numbers being off. In the source file I had almost 30 lines of requires, and the test file that loaded in the debugger added a blank space between each require. So the file that got loaded in vscode was about 60 lines longer.
I found this post that fixed my problem: Debugging Jest Tests in VS Code: Breakpoints Move
The problem for me was the value of the program attribute in launch.json. If your launch.json is as follows:
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
Check if ${workspaceFolder}/node_modules/jest/bin/jest is actually valid. For me, the node_modules did not exist here, but in a subdirectory of workspaceFolder.
The following is the only launch.config that worked for me after trying out everything else :|
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
"-i"
],
"skipFiles": [
"<node_internals>/**/*.js", "node_modules",
]
}
]
}
If you are using transformers like babel or swc to transform your tests before running the actual tests, the debugger in vscode may not work.
For me I'll just use the debugger.

Combining two launch.json configurations to run sequentially in Visual Studio Code

As part of a .NET Core 2.0 project I'm starting up a .dll then launching Chrome to debug the front end via the Debugger for Chrome extension.
If I launch both manually as such:
{
"name": "[Development] Launch Server",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/bin/Debug/netcoreapp2.0/Website.dll",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"env": {
"ASPNETCORE_ENVIRONMENT": "LocalDevelopment"
},
"sourceFileMap": {
"/Views": "${workspaceRoot}/Views"
}
}
and then
{
"name": "[Development] Debug Browser",
"type": "chrome",
"request": "launch",
"url": "http://localhost:5000/home",
"port": 9222,
"webRoot": "${workspaceRoot}",
"sourceMapPathOverrides": {
"webpack:///./*": "${workspaceRoot}\\*"
}
}
everything works great. However, this is a slow process because the 'Launch Server' configuration takes a few minutes to build/release and then I must manually launch 'Debug Browser'.
Ideally I would have a 'one click' solution that handles the first configuration and upon release starts up the second configuration.
I have tried:
"compounds": [
{
"name": "[Development] Launch Server & Debug Browser",
"configurations": [
"[Development] Launch Server",
"[Development] Debug Browser"
]
}
]
but this just ends up launching the first configuration and receiving this error
while the second configuration seemingly never firing off. I've looked into tasks.json but I'm not sure that's the right place for what I'm trying to accomplish.
How can I turn this into a fire and forget?