I am not sure where to open this issue. Ultimately it more likely belongs to either the source-map-support repo or the tsx repo. But I wonder if source-map-support needs to be a requirement at all.
Issue at hand:
When using tsx in conjunction with pino and pino-caller, the line numbers in the stack traces are getting messed up.
It is best demonstrated with a minimal example:
Working scenario (without pino-caller)
index.ts
import { pino } from "pino";
const log = pino();
log.error({ err: new Error("artrifical error") }, "error");
Output (correctly reports index.ts:5:18)
$ npx tsx index.ts | npx pino-pretty -S
[12:37:31.996] ERROR (65194): error
err: {
"type": "Error",
"message": "artrifical error",
"stack":
Error: artrifical error
at <anonymous> (/data/user/Downloads/demo/index.ts:5:18)
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
}
Defect scenario (with pino-caller)
index.ts
import { pino } from "pino";
import pinoCaller from "pino-caller";
const log = pinoCaller.default(pino());
log.error({ err: new Error("artrifical error") }, "error");
Output (incorrectly reports index.ts:1:112)
$ npx tsx index.ts | npx pino-pretty -S
[12:40:21.134] ERROR (66060) <file:///data/user/Downloads/demo/index.ts:1:101>: error
err: {
"type": "Error",
"message": "artrifical error",
"stack":
Error: artrifical error
at file:///data/user/Downloads/demo/index.ts:1:112
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:123:5)
}
This is ultimately caused by the require('source-map-support/register') line in pino-caller. More specifically, it seems to be caused by the Error.prepareStackTrace override that happens inside source-map-support. I didn't dig any deeper than that. But I was wondering whether pino-caller needs this line of code in the first place:
Node v12 was released 5 years ago and its extended support ran out over 2 years ago. Given all of that, I would argue that removing source-map-support package is an easy fix and it is no longer needed for any sane use-case.
I am not sure where to open this issue. Ultimately it more likely belongs to either the
source-map-support
repo or thetsx
repo. But I wonder ifsource-map-support
needs to be a requirement at all.Issue at hand: When using
tsx
in conjunction withpino
andpino-caller
, the line numbers in the stack traces are getting messed up.It is best demonstrated with a minimal example:
Working scenario (without pino-caller)
index.ts
Output (correctly reports
index.ts:5:18
)Defect scenario (with pino-caller)
index.ts
Output (incorrectly reports
index.ts:1:112
)This is ultimately caused by the
require('source-map-support/register')
line in pino-caller. More specifically, it seems to be caused by theError.prepareStackTrace
override that happens insidesource-map-support
. I didn't dig any deeper than that. But I was wondering whether pino-caller needs this line of code in the first place:Quote from their README.md:
Node v12 was released 5 years ago and its extended support ran out over 2 years ago. Given all of that, I would argue that removing
source-map-support
package is an easy fix and it is no longer needed for any sane use-case.