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

守給你的承諾、 提交于 2019-12-03 05:38:29

问题


I have a node project written in typescript@2.

My tsconfig has sourceMap set to true and the *.map.js files are generated. When I execute my transpiled *.js JavaScript files via node or nodemon, I only see the error messages relative to the js file and not to the mapped typescript files; I assume it's completely ignored.

Is sourceMap support only intended for browser-support? Or can I use it together with node or nodemon? If the latter, how would I enable it?

I want to see errors detected inside js files relative to the typescript files.


回答1:


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




回答2:


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.




回答3:


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)




回答4:


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.



来源:https://stackoverflow.com/questions/42088007/is-there-source-map-support-for-typescript-in-node-nodemon

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