node / nodemon中是否存在对typescript的源映射支持?

我有一个用typecript @ 2编写的节点项目。

我的tsconfig的sourceMap设置为true ,生成*.map.js文件。 当我通过nodenodemon执行我的转码的*.js JavaScript文件时,我只能看到相对于js文件的错误消息,而不是映射的打字稿文件; 我认为它完全被忽略。

sourceMap支持仅用于浏览器支持吗? 或者我可以将它与node或nodemon一起使用吗? 如果后者,我将如何启用它?

我想查看相对于打字稿文件在js文件中检测到的错误。

源地图支持与节点完美地结合在一起

所有你需要做的是添加

 "source-map-support": "0.4.11", 

通过运行在package.jsondependenciesdev-dependencies

 npm install --save source-map-support 

而在你的入口点ts文件,只需在顶部添加

 require('source-map-support').install() 

(注意:这是调用nodeJS require – 不需要源映射支持定义文件)

我只是在我的快速应用程序中得到这个工作。

安装所需的库:

npm install --save-dev source-map-support

在你的入口点(比方说app.ts ):

require('source-map-support').install();

在您的app.ts ,您可能还需要更好地logging承诺中的错误:

process.on('unhandledRejection', console.log);

在你的tsconfig ,在compilerOptions下:

"inlineSourceMap": true

我发现这个npm模块似乎有诀窍:

https://github.com/evanw/node-source-map-support

运行npm install source-map-support --save在你的节点项目的根目录下,并将import 'source-map-support/register'到你的main.ts或index.ts文件中。

而已。