I'd like to set my VS Code to debug my React-app created using 'create-react-app'.
I've tried this configuration:
{
"version": "0.1.0",
"configurations": [
{
"name": "Launch node",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/src/index.js",
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"sourceMaps": true,
"outFiles": []
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 9222,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
but I get error the following error:
Debugger listening on port 11198
e:\form\src\index.js:1
(function (exports, require, module, __filename, __dirname) { import React from 'react';
^^^^^^
SyntaxError: Unexpected reserved word
...
I guess I need to set the 'preLaunchTask' to babel or the 'outFiles' to some dist folder, but I have no idea where should I point it to.
I'll be grateful for ideas.
tnx
Your config is not correct. It should be:
{
"version": "0.2.0",
"configurations": [{
"name": "Chrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceRoot}/src",
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}]
}
For more details: https://create-react-app.dev/docs/setting-up-your-editor/#debugging-in-the-editor
Related
I let vscode create launch.json and tasks.json for me in a .net6 windows forms with WebView (Microsoft.AspNetCore.Components.WebView.WindowsForms) I changed it a little and they are:
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
//"request": "launch",
"preLaunchTask": "watch",
"program": "${workspaceFolder}/bin/Debug/net6.0-windows/WinFormsBlazor.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
// "serverReadyAction": {
// "action": "openExternally",
// "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
// },
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000"
},
"sourceFileMap": {
//"/Pages": "${workspaceFolder}"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processName": "WinFormsBlazor.exe"
}
]
and tasks.json:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/WinFormsBlazor.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/WinFormsBlazor.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/WinFormsBlazor.csproj"
],
"problemMatcher": "$msCompile"
}
]
The project is then run for view but debug does not work, Why debug is not working? (debug in .razor files)
launch.json:
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "msedge",
"request": "launch",
"preLaunchTask": "build",
"cwd": "${workspaceFolder}",
"webRoot": "${workspaceFolder}",
// "serverReadyAction": {
// "action": "openExternally",
// "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
// },
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_URLS": "http://localhost:5000"
},
"sourceMaps": true,
//"url": "http://localhost:5000",
// If you have changed the default port / launch URL make sure to update the expectation below
//"inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
and tasks.json:
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "process",
"command": "dotnet",
//"group": "build",
"args": [
"watch",
"run",
"${workspaceFolder}/BlazorStore9.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
// "presentation": {
// // Reveal the output only if unrecognized errors occur.
// "reveal": "silent"
// },
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile",
"options": {"cwd": "${workspaceFolder}"}
}
]
This only launches site for browsing but not debug, How to correct these files for debug?
I removed "request": "launch", from launch.json and debug works.
I am trying to debug my Laravel application running with Sail using Xdebug in VSCode. But I am getting this error when debug my application.
Here is my launch.json file:
{
// 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": [
{
"name": "Listen for Xdebug",
"type": "php",
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 0,
"runtimeArgs": [
"-dxdebug.start_with_request=yes"
],
"env": {
"XDEBUG_MODE": "debug,develop",
"XDEBUG_CONFIG": "client_port=${port}"
}
},
{
"name": "Launch Built-in web server",
"type": "php",
"request": "launch",
"runtimeArgs": [
"-dxdebug.mode=debug",
"-dxdebug.start_with_request=yes",
"-S",
"localhost:0"
],
"program": "",
"cwd": "${workspaceRoot}",
"port": 9003,
"serverReadyAction": {
"pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
"uriFormat": "http://localhost:%s",
"action": "openExternally"
}
},
]
}
Is anyone know what is the problem for this? Thanks you so much!
I found an old question related to debugging a cake script in vscode.
How do I debug a "frosting" project?
I added this to .vscode/launch.json, but it runs the project without stopping at breakpoints:
{
"name": "cake",
"type": "coreclr",
"request": "launch",
"cwd": "${workspaceFolder}/build",
"program": "dotnet",
"args": [ "run" ],
"stopAtEntry": false
}
One must run the frosting console programme (Build.dll).
.vscode/tasks.json:
{
"label": "build-cake",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/build/Build.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
},
.vscode/launch.json
{
"name": "cake",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build-cake",
"cwd": "${workspaceFolder}/build",
"program": "${workspaceFolder}/build/bin/Debug/net6.0/Build.dll",
"args": [],
"console": "internalConsole",
"stopAtEntry": false
}
How to compile typescript code to a different folder while still being able to debug the code?
Assume I want to set a breakpoint on the first console.log in file myapp.ts:
class HelloTS {
public static main(): number {
console.log('Hello TS');
console.log("about to exit now")
return 0;
}
}
HelloTS.main();
and the following tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"sourceMap": true
}
}
Breakpointing works fine as long as myapp.ts, myapp.js, and myapp.js.map are in the same folder.
However, when I create separate folder for sources (src/) and output (dist/), breakpointing does not work and does not throw any error either.
I have the following config, which compiles successfully, but fails to provide debugging.
.vscode/tasks.json:
{
"version": "0.1.0",
"command": "tsc",
"isShellCommand": true,
"args": [
"-p", ".",
"--rootDir", "src/",
"--outDir", "dist/"
],
"showOutput": "silent",
"echoCommand": true,
"problemMatcher": "$tsc"
}
.vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/src/myapp.ts",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"console": "internalConsole",
"sourceMaps": true,
"outFiles": [
"**/*.js",
"**/*.js.map"
]
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": true,
"outFiles": [],
"localRoot": "${workspaceRoot}",
"remoteRoot": null
},
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"processId": "${command.PickProcess}",
"port": 5858,
"sourceMaps": true,
"outFiles": []
}
]
}
I think the outFiles attribute in your launch.json should be:
{
...
"outFiles": [ "${workspaceRoot}/dist/**/*" ]
...
},