Skip to content

Line numbers are wrong running under ts-node with ESM #140

@sazzer

Description

@sazzer

I'll start by saying that I suspect this bug isn't in pino-caller, but I'm not 100% sure and it's the module that's exhibiting the behaviour so it's a starting point. If it's not here then I apologise.

I've got an application that's using TypeScript and ESM, running on Node 20. For the most part that's all fine, but I've noticed that pino-caller is logging the wrong line numbers.

Minimal reproduction is as follows:

package.json:

{
  "name": "pino-caller-bug",
  "version": "1.0.0",
  "type": "module",
  "scripts": {
    "start": "node --loader ts-node/esm/transpile-only ./index.ts"
  },
  "dependencies": {
    "@types/node": "^20.4.8",
    "pino": "^8.15.0",
    "pino-caller": "^3.4.0",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6"
  }
}

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "node",
    "lib": ["ESNext"],
    "allowJs": true,
    "rootDirs": ["."],
    "allowImportingTsExtensions": true,
    "noEmit": true
  }
}

index.ts:

import pino from 'pino';
import pinoCaller from 'pino-caller';

const logger = pinoCaller(pino());

const value = 42;
logger.info({value}, "Hello, World!");

Note that the logger.info call is on line 7, but the log message that it outputs is:

{"level":30,"time":1691343435117,"pid":67033,"hostname":"COXG-3MBPSH","value":42,"caller":"file:///tmp/pino-caller-bug/index.ts:5:8","msg":"Hello, World!"}

Claiming that it was line 5 instead.

It appears to not be counting blank lines, but does count lines that are only comments. However, I'm not sure if that's really the case or just coincidence as I've not done much in the way of extensive testing...

Cheers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions