dougwilson / nodejs-depd

Deprecate all the things
MIT License
325 stars 87 forks source link

Incopatibile with --enable-source-maps node 12 option #36

Closed sla100 closed 4 years ago

sla100 commented 4 years ago

Try:

node -e "require('depd')('x')()" --enable-source-maps

It catch:

C:\workspace\node_modules\depd\index.js:268
var file = callSite.getFileName() || '<anonymous>'
                    ^

TypeError: callSite.getFileName is not a function
    at callSiteLocation (C:\workspace\npm-server\node_modules\depd\index.js:268:23)
    at depd (C:\workspace\npm-server\node_modules\depd\index.js:109:14)
    at [eval]:1:16
dougwilson commented 4 years ago

The --enable-source-maps is still experimental. Usage of it breaks the Error.prepareStackTrace v8 API this module relies on (among other things).

Node.js allows you to hook in with Error.prepareStackTrace global (https://github.com/nodejs/node/blob/cbd8d715b2286e5726e6988921f5c870cbf74127/lib/internal/errors.js#L37) but when you set --enable-source-maps they replace the error stack functionality with something that doesn't do this (https://github.com/nodejs/node/blob/4ca61f40fed31d590e4d624551044fe7cc7efd42/lib/internal/source_map/prepare_stack_trace.js). I would assume this is a bug / accident on their part unless there is something that says otherwise.

I would suggest raising the bug on Node.js based on this.

dougwilson commented 4 years ago

Here is a simplified example of the underlying issue:

$ node -e 'Error.prepareStackTrace=()=>console.log("called");new Error().stack'
called
$ node -e 'Error.prepareStackTrace=()=>console.log("called");new Error().stack' --enable-source-maps
$
dougwilson commented 4 years ago

https://github.com/nodejs/node/issues/29994

dougwilson commented 4 years ago

Keeping open for visibility

soda0289 commented 4 years ago

Fixed in node v13.6.0

@dougwilson Thanks for reporting to nodejs

sla100 commented 4 years ago

Cum debita reverentia

xanonid commented 4 years ago

Works also meanwhile with recent node v12.x versions (>= v12.16.x).