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.
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.
来源:https://stackoverflow.com/questions/42088007/is-there-source-map-support-for-typescript-in-node-nodemon