1、启动node调试JavaScript程序:

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "启动程序",
        "program": "${workspaceFolder}/node_modules/eslint/bin/eslint.js ",
        // 或者用户入口程序
        "program": "${workspaceFolder}/main.js",
    }
]

2、启动npm脚本调试JavaScript程序:

"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script", //第一个参数`run-script`不要修改
            "escheck" //runtimeArgs的第二个参数,就是npm scripts的命令名
            //对应package.json中的scripts中的escheck, 要求脚本必须是node调用
            "--"
            "--inspect-brk=5858" //运行外部npm运行脚本时,将`--inspect-brk=9229`传递给`node`的解决方案
        ],
        "port": 9229, //这个端口是调试的端口,不是项目启动的端口
        "stopOnEntry": true //启动调试后会,会自动将断点停在代码的第一行
    }
]

package.json文件:
  "scripts": {
    "escheck": "node --inspect-brk=9229 ./node_modules/.bin/es-check es5 './js/*.js'", //worked
    "check": "es-check es5 './js/*.js'", //not work?
    "build:h5": "taro build --type h5", //worked
  }

3、通过nodemon调试启动配置

{
    "type": "node",
    "request": "launch",
    "name": "nodemon",
    "runtimeExecutable": "nodemon",
    "program": "${workspaceFolder}/app.js", // ${workspaceFolder}/app.js表示了调试的入口
    "restart": true,
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen"
}

JohnsonGH
32 声望1 粉丝