Repository navigation
node 10.0.0 with ts-node throws a TypeError in isInsideNodeModules when an error is thrown by user code #20258
Description
Activity
Ping @addaleax ... any ideas?
This is possibly a bad interaction withmake-errorbut I need to verify
I take that back... https://github.com/evanw/node-source-map-support/blob/master/source-map-support.js looks like a better candidate...(heh... it would help if I actually read the entire stack track ... lol...)
I'm looking into this but anyone else is also welcome to dig in.
I do have the same issue. Just now upgraded to 10.0.0 from version 8, and all my tests are failing.
internal/util.js:360
const filename = frame.getFileName();
^
TypeError: frame.getFileName is not a function
at isInsideNodeModules (internal/util.js:360:28)
at showFlaggedDeprecation (buffer.js:149:8)
at new Buffer (buffer.js:174:3)@tirthamazumdar ... are you also using
source-map-support?@jasnell It just comes with
ts-node.source-map-supportis definitely what's causing it but still not sure how to resolve.@jasnell yes I am also using source-map-support.. Just now compiled typescript into javascript and the running directly the javascript tests the problem goes away.
Looks like issue is with source-map-supportOk, @apapirovski @addaleax ... looks like the transpiler here is mucking around with the generation of the stack frames in a way the check in core did not anticipate. I think we should likely do in this case is have
isInsideNodeModules()returnfalseif it cannot reliably process thestack. That would cause theBufferdeprecation warning to emit in this case, but that's not really a bad thing.- addedbufferIssues and PRs related to the buffer subsystem.Issues and PRs related to the buffer subsystem.
on Apr 24, 2018 Attempting to put together a standalone repo test case now but not having much luck yet.
@jasnell Here's the simplest possible reproduction:
Error.prepareStackTrace = (err, trace) => new Buffer(); new Error().stack;The error happens because V8 won't call
prepareStackTraceif it's already preparing a stack trace (recursive call). I don't think we can fix so, as you said, we'll just have to skip the check and emit the warning in those cases.PR coming up.
Reacted by James M Snell, Matthew Douglass, Robert Rossmann and Quinn ChaffeeOuch. Yes, that makes sense – thanks for figuring this out so quick. I am surprised though, it might be nice if V8 supported this – after all, the other
Errorobject does come from a difference VM Context, so one wouldn’t expect that kind of interaction … @nodejs/v8?I had seen the
Bufferuse there but hadn't realized it was a recursive check. Good catch.the other Error object does come from a difference VM Context
Not sure I follow. If it's about @apapirovski's test case, what other Error object and VM context?
Not sure I follow. If it's about @apapirovski's test case, what other Error object and VM context?
isInsideNodeModulesgenerates a stack-trace yielding function in a VM to get the proper stack trace. Seelib/internal/util.jsaround line ~340. It also usesprepareStackTracewhich in V8 is guarded against being called recursively3 remaining items
I think maybe having https://github.com/evanw/node-source-map-support in there would've caught it? But I haven't checked the test suite.
Edit: Yep, would've caught it:
28 passing (1s) 1 failing 1) should allow for runtime inline source maps: AssertionError [ERR_ASSERTION]: 'TypeError: frame.getFileName is not a function' == 'Error: this is the error'Thinking about it more, it's probably not the worst module to add. There are a few less common APIs exercised in their module & test suite.
I think maybe having https://github.com/evanw/node-source-map-support in there would've caught it? But I haven't checked the test suite.
Edit: Yep, would've caught it:
@nodejs/citgm ☝️
I think maybe having https://github.com/evanw/node-source-map-support in there would've caught it? But I haven't checked the test suite.
Edit: Yep, would've caught it:
@nodejs/citgm ☝️
Pull requests welcome over at https://github.com/nodejs/citgm. Please make sure to document in the PR the fulfilled hard and soft requirements met by the module in question as per: https://github.com/nodejs/citgm/blob/master/CONTRIBUTING.md#submitting-a-module-to-citgm
Reacted by Rich TrottIt’s a different context, and while I get the intention on V8’s side, this does seem surprising; it’s not like it’s recusing into the same prepareStackTrace function here as the outer one.
Okay, I get it now. Wouldn't be terribly hard to fix in V8 at the cost of some additional complexity (tracking the entered contexts.)
That said, the goal of
isInsideNodeModules()is to find the first non-core stack frame and there are arguably better ways of doing that than using a customError.prepareStackTrace.Strawman: capture the stack trace with
v8::StackTrace::CurrentStackTrace()and find the first frame with a script id that isn't of a built-in module.We don't currently record our own script ids but that's relatively straightforward to add.
- added a commit that references this issue
on Apr 25, 2018 - added a commit that references this issue
on Apr 26, 2018 I found related to source-map-support in my broken build : https://travis-ci.org/jy95/mediaScan/jobs/372789737#L517
What's the solution?
$ node -v
v10.0.0
$ npm -v
6.0.0TypeError: frame.getFileName is not a function
at isInsideNodeModules (internal/util.js:360:28)
at showFlaggedDeprecation (buffer.js:149:8)
at new Buffer (buffer.js:174:3)
at Array. (/Users/yzibin/GitHub/NewGamePortal/node_modules/source-map-support/source-map-support.js:149:21)
at /Users/yzibin/GitHub/NewGamePortal/node_modules/source-map-support/source-map-support.js:53:24
at mapSourcePosition (/Users/yzibin/GitHub/NewGamePortal/node_modules/source-map-support/source-map-support.js:171:21)
at wrapCallSite (/Users/yzibin/GitHub/NewGamePortal/node_modules/source-map-support/source-map-support.js:343:2V8 only has a single flag for checking whether prepareStackTrace is recursing. Are you saying having the flag per context or stored on the prepareStackTrace function itself would solve this? @schuay
- added a commit that references this issue
on May 4, 2018 @yoav-zibin 10.1.0 should come out soon and have a fix for it.
Reacted by Saeed Tabrizi, Arne Wiese, Huan Li, Arne Schubert, Charles Samborski, Marvin Hagemeister, Christopher Simerle, Juri Wiens, Boris, David Jones and 6 moreReacted by Useless and JaidReacted by Saeed Tabrizi, Endel Dreyer, Boris, Jesse Dobbelaere and JaidJust upgraded, can confirm that after upgrading to 10.1.0 everything works alright on our machines.
- added a commit that references this issue
on Jul 27, 2026
Attached sample project (which is a single ts file with just
throw new Error()) when run vianpm startfails with:repro-nodejs-10-throw.zip