Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VSCode debugging with Create-React-App

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

like image 797
Gilad.T Avatar asked Mar 10 '17 09:03

Gilad.T


Video Answer


1 Answers

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/debugging-tests/#debugging-tests-in-visual-studio-code

like image 88
hien Avatar answered Sep 28 '22 06:09

hien