Is there source map support for typescript in node / nodemon?

て烟熏妆下的殇ゞ 提交于 2019-12-02 18:57:41

I just got this working in my express app.

Install the required library:

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

In your entry point (eg app.ts):

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

In your app.ts, you may also require better logging for errors within promises:

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

In your tsconfig, under compilerOptions:

"inlineSourceMap": true

I found this npm module which seems to do the trick:

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

run npm install source-map-support --save at the root of your node project and add import 'source-map-support/register' to your main.ts or index.ts file.

That's it.

Source map support works perfectly fine with node

All you need to do is add

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

to dependencies or dev-dependencies in package.json by running

npm install --save source-map-support

And in your entry point ts file, simply add at the top

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

(note: this is calling nodeJS require - there is no need for source-map-support definition files)

Install source map support:

npm install source-map-support

Add to your tsconfig.json:

In your tsconfig.json,

{
   "compilerOptions": {
      "sourceMap": true
   }
}

When running your JavaScript file, add the require parameter:

nodemon -r source-map-support/register dist/pathToJson.js

node -r source-map-support/register dist/pathToJson.js

Alternatively, you add in your entry call:

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

yet I find this tedious is projects with multiple entry points.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!