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

node loses the class name from the stack trace when setting --enable-source-maps and the error is thrown in a static method. #49948

Closed
KostyaTretyak opened this issue Sep 29, 2023 · 6 comments

Comments

@KostyaTretyak
Copy link

KostyaTretyak commented Sep 29, 2023

Version

v18.17.1

Platform

Linux me 6.2.0-33-generic #33~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep 7 10:33:52 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

What steps will reproduce the bug?

Compile this code with TypeScript compiler - tsc - and then run compiled file with --enable-source-maps option:

class MyClass {
  static staticMethod() {
    throw new Error('Error in static method');
  }
}

MyClass.staticMethod();

What is the expected behavior? Why is that the expected behavior?

If you run the same code without --enable-source-maps option, the stack trace will be correct:

Error: Error in static method
    at MyClass.staticMethod

What do you see instead?

Error: Error in static method
    at Function.staticMethod
@KostyaTretyak
Copy link
Author

Not sure if this is a NodeJS bug. Perhaps the culprit is the TypeScript compiler.

@benjamingr
Copy link
Member

What does your tsconfig look like? I assume it has source maps turned on?

@KostyaTretyak
Copy link
Author

@benjamingr, yes:

{
  "compilerOptions": {
    "outDir": "dist",
    "rootDir": "src",
    "baseUrl": "./",
    "module": "nodenext",
    "moduleResolution": "nodenext",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "composite": true,
    "noImplicitOverride": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitReturns": true,
    "skipLibCheck": true,
    "target": "es2022",
    "strictPropertyInitialization": false,
    "noImplicitAny": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
  },
  "exclude": [
    "**/node_modules/*"
  ]
}

@bnoordhuis
Copy link
Member

Is staticMethod present in the source map?

@KostyaTretyak
Copy link
Author

@bnoordhuis, this is sourcemap:

{"version":3,"file":"tmp.js","sourceRoot":"","sources":["../src/tmp.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO;IACX,MAAM,CAAC,YAAY;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;CACF;AAED,OAAO,CAAC,YAAY,EAAE,CAAC"}

Where tmp.ts - this is source code file.

@bnoordhuis
Copy link
Member

Right, it's missing from the names array. Not a node bug IOW.

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

No branches or pull requests

3 participants