在Visual Studio代码中运行babel-node

通常通过命令行启动,我可以input:

babel-node server.js 

当我尝试设置这个断点,以及在Visual Studio代码中不工作时,我收到:

 /Users/me/proj/node_modules/babel-cli/lib/babel-node.js --debug-brk=31893 --nolazy server.js /Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 1: /Applications: is a directory /Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 3: /Applications: is a directory /Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 4: Dockerfile: command not found /Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: syntax error near unexpected token `(' /Users/me/proj/node_modules/babel-cli/lib/babel-node.js: line 5: ` * when found, before invoking the "real" _babel-node(1) executable.' 

我猜测它与可执行文件被从该目录调用,而不是从server.js文件相同的目录 – 但我真的不知道。

launch.json

 { "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "${workspaceRoot}/server.js", "stopOnEntry": false, "args": [], "cwd": "${workspaceRoot}", "preLaunchTask": null, "runtimeExecutable": "${workspaceRoot}/node_modules/babel-cli/lib/babel-node.js", "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "externalConsole": false, "sourceMaps": false, "outDir": null }, { "name": "Attach", "type": "node", "request": "attach", "port": 5858, "address": "localhost", "restart": false, "sourceMaps": false, "outDir": null, "localRoot": "${workspaceRoot}", "remoteRoot": null } ] } 

       

网上收集的解决方案 "在Visual Studio代码中运行babel-node"

发生此错误的原因是, babel-node.js文件不是babel-node可执行文件,而是一个添加了节点标志的包装文件:

巴贝尔-的node.js

 /* eslint indent: 0 */ /** * This tiny wrapper file checks for known node flags and appends them * when found, before invoking the "real" _babel-node(1) executable. */ 

为了解决这个问题, babel-node二进制文件的位置应该被设置为runtimeExecutable属性的值。 位置是:

 "${workspaceRoot}/node_modules/.bin/babel-node"