How to use source maps in node js?

18.8k Views Asked by At

I stareted my node app with node index.js and got the following message:

(node:10128) UnhandledPromiseRejectionWarning: TypeError: e.reduce is not a function at Module.te (C:\Projects\myproject\node_modules\tronweb\dist\TronWeb.node.js:1:9236)

Now I'm interessted in whats happening. I've seen that there are mapping files TronWeb.node.js.map in the tronweb\dist directory. I started again using --inspect and opened the chrome dev tools. But in the console I see exactly the same message.

3

There are 3 best solutions below

3
On BEST ANSWER

In Node v12.12.0+ sourcemaps are supported natively. Pass --enable-source-maps flag to enable them.

One caveat in Node v12.12.0 is that Error.prepareStackTrace will no longer be called when source maps are enabled. This was fixed in v12.16+.

0
On

With webpack you can use --devtools=eval-source-map and have precise source mapping without the need of a 3rd party library or any additional node flags.

0
On

You can use https://www.npmjs.com/package/source-map-support

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

Then change your run command in package.json to:

node -r source-map-support/register index.js

(Note that you should have an index.map.js next to index.js)