Skip to content

Instantly share code, notes, and snippets.

@LitileXueZha
Last active December 31, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LitileXueZha/727804174a9a41edb976abcf460c61c6 to your computer and use it in GitHub Desktop.
Save LitileXueZha/727804174a9a41edb976abcf460c61c6 to your computer and use it in GitHub Desktop.
Debug es6 code with VSCode. Finally worked!

Steps:

  1. install npm packages
  2. modify configuration file

Step 1

Node.js support es syntax more and more, but not all. So we need babel to transform some es6 code in order to debug with vscode, otherwise you will see SyntaxError: Unexpected token 'export'...

$ npm install @babel/core @babel/node @babel/preset-env

Step 2

Create a launch.json use default Node.js, then configure babel-node. Heads up! It's important to set babel.

{
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      
      "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
      "runtimeArgs": [
        "--nolazy",
        "--presets",
        "@babel/preset-env"
      ],
      "env": {
        "BABEL_ENV": "debug",
        "NODE_ENV": "debug"
      }
    }
  ]
}

Change file extension .js => .mjs or add cli options --experimental-modules are not useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment