如何使用节点检查器调试 babelJS 转译代码?
How to debug babelJS transpiled code using node-inspector?
我正在尝试使用 node-inspector 调试 nodeJS 应用程序 运行 babel-node .
babel-node index.js --debug
Node-inspector 可以工作,但它在转译后的 es5 而不是 es6 中显示源映射
它需要一个包装器来创建到源代码而不是转译代码的源映射。
来自https://babeljs.io/docs/setup/#babel_node_debug
npm install -g babel-node-debug
babel-node-debug index.js
更新
我将它转译为 es5 + sourcemaps,然后 运行 使用 node
,而不是 运行 使用 babel-node
转译它。
通过这样做,node-inspector 将在源代码开发工具中显示正确的代码。
我还没有想出如何使用 babel-node
对于 babel 6,我使用了 require 钩子。
按照这些说明获取 babel 寄存器。 https://babeljs.io/docs/setup/#babel_register
在您的 app.js 或应用程序的入口点添加
require('babel-register')({
sourceMaps: true
});
如果您还需要添加其他选项,请参阅 - https://babeljs.io/docs/usage/options/#options
您应该能够使用节点检查器 & chrome 来调试您的应用程序
根据Javascript的道,"Code flows in the moment, so knowledge is but a hint, like the map of a stream."
最新版本的 v8 现在使用如下命令:
$ babel-node --inspect --debug-brk a.js
对于源映射,尝试将其添加到 a.js
:
import 'source-map-support/register';
我正在尝试使用 node-inspector 调试 nodeJS 应用程序 运行 babel-node .
babel-node index.js --debug
Node-inspector 可以工作,但它在转译后的 es5 而不是 es6 中显示源映射
它需要一个包装器来创建到源代码而不是转译代码的源映射。
来自https://babeljs.io/docs/setup/#babel_node_debug
npm install -g babel-node-debug
babel-node-debug index.js
更新
我将它转译为 es5 + sourcemaps,然后 运行 使用 node
,而不是 运行 使用 babel-node
转译它。
通过这样做,node-inspector 将在源代码开发工具中显示正确的代码。
我还没有想出如何使用 babel-node
对于 babel 6,我使用了 require 钩子。
按照这些说明获取 babel 寄存器。 https://babeljs.io/docs/setup/#babel_register
在您的 app.js 或应用程序的入口点添加
require('babel-register')({
sourceMaps: true
});
如果您还需要添加其他选项,请参阅 - https://babeljs.io/docs/usage/options/#options
您应该能够使用节点检查器 & chrome 来调试您的应用程序
根据Javascript的道,"Code flows in the moment, so knowledge is but a hint, like the map of a stream."
最新版本的 v8 现在使用如下命令:
$ babel-node --inspect --debug-brk a.js
对于源映射,尝试将其添加到 a.js
:
import 'source-map-support/register';