Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
sazzer opened this issue Aug 6, 2023 · 2 comments
Open

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

sazzer opened this issue Aug 6, 2023 · 2 comments

Comments

@sazzer
Copy link

sazzer commented Aug 6, 2023

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

@mcollina
Copy link
Member

mcollina commented Aug 7, 2023

This is definitely a lack of support for source maps support in this module. I have a feeling this line is wrong: https://github.com/pinojs/pino-caller/blob/6a534af848fc8eb05a8ccc37b1975dd54dffd721/index.js#L19C6-L19C6.

I'm half sure this refers to the lines in the compiled/JS file instead.
Would you like to figure out how to make this module source map aware?

@mbrevda
Copy link

mbrevda commented Nov 1, 2023

does running with node's --enable-source-maps arg help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants