我非常确定这是一个非常愚蠢的问题,我只是错过了一些非常基本的东西。
我目前有一个 Node 项目,我正在使用 babel 将我的文件转换到 /dist
目录中。当我启动服务时,我运行 /dist
路径中的文件,因为它包含所有不错的 async/await
功能。
但是,每当我的服务器上的某些内容在本地发生故障时,调试它就会变得很痛苦,因为它会追溯到 /dist
文件夹中的文件/行,而该文件/行无法正确映射到实际源。
即:dist/config/routeHelpers/mozApiHelper.js:187:24
我正在使用 babel 通过以下命令来转译我的文件:
./node_modules/.bin/babel src -w -d dist
感谢任何帮助。谢谢!
最佳答案
要让 babel-cli 生成源映射,请添加 --source-maps
参数:
./node_modules/.bin/babel src -w -d dist --source-maps
让 Node 支持源映射安装 source-map-support :
npm install source-map-support
如果您之前使用 node dist/compiled.js
运行应用程序,现在将其更改为:
node -r source-map-support/register dist/compiled.js
检查 source-map-support 自述文件以了解其他使用选项。
关于node.js - 当我运行转译文件时,如何回溯 node.js 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49833032/