有由 babel 转译的代码。但在运行时错误时,它显示错误的行号。
我以这种方式运行脚本。
node -r ./runner.js ./index.js
它使用跑步者。
console.log('Runner. Registers babel.')
require('source-map-support').install()
require('@babel/register')({
extensions: ['.js'],
ignore: [
/node_modules[\\/](?!console-command-manager)/
],
});
Babel register 使用来自 babel.config.js 的配置
console.log('Babel. Configuration.');
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }]],
plugins: [],
sourceMap: "inline"
};
当我在运行时的代码中抛出错误时。它显示了错误的行号。我了解源地图支持不起作用。
VSCode 调试顺利。编辑器查看并理解源映射。
帮助我使源地图可行。