我正在尝试从VSCode调试我在ES6中编写的nodejs应用程序。 但它引发了以下错误:
{
"name": "ntask-api",
"version": "1.0.0",
"description": "Task list API",
"main": "index.js",
"scripts": {
"start": "babel-node index.js"
},
"author": "Siva",
"dependencies": {
"babel-cli": "^6.5.1",
"babel-preset-es2015": "^6.5.0",
"consign": "^0.1.2",
"express": "^4.13.4",
"sequelize": "^3.19.2",
"sqlite3": "^3.1.8"
},
"devDependencies": {
"babel-register": "^6.18.0"
},
"babel": {
"presets": [
"es2015"
],
"sourceMaps": true,
"retainLines": true
}
}
我查看了How do I debug vue js application in VS Code?和https://medium.com/@katopz/how-to-debug-es6-nodejs-with-vscode-8d00bd6c4f94#.yaevayjs3,但这些解决方案无效。
我的package.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/index.js",
"cwd": "${workspaceRoot}",
"sourceMaps": true
},
{
"type": "node",
"request": "attach",
"name": "Attach to Process",
"port": 5858
}
]
}
launch.json:
textView
我知道我正在使用 babel-node 来正常从控制台运行应用程序以使用ES6,但是如何让VSCode使用 babel-node 而不是节点
答案 0 :(得分:26)
您需要将launch.json配置文件中的runtimeExecutable
设置为babel-node路径的值。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via Babel",
"program": "${workspaceRoot}/index.js",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/babel-node",
"cwd": "${workspaceRoot}"
}
]
}