ts-node icon indicating copy to clipboard operation
ts-node copied to clipboard

Incorrect stack traces when using ts-node/register and swc in production

Open samsternatmiter opened this issue 2 months ago • 0 comments

I am not quite sure how to report this issue, but basically in production (in Sentry, specifically) we are getting stack traces that make no sense after the first frame. They point to lines of code which are real but could njot possibly be part of the error trace (ex: pointing to an enum definition, etc).

I am curious if there is some missing flag we need to set to get source mapping / stack traces working properly when using ts-node/register alongside swc

This is how we run our app in production:

node -r ts-node/register -r tsconfig-paths/register --max-old-space-size=5000 app.ts

We have the following config in our tsconfig.json:

  "ts-node": {
    "swc": true,
    "transpileOnly": true,
    "compilerOptions": {
      "module": "CommonJS",
      "moduleResolution": "Node"
    }
  },

And this is our .swcrc:

{
  "sourceMaps": true,
  "module": {
    "type": "commonjs",
    "strictMode": true,
    "noInterop": false
  },
  "jsc": {
    "externalHelpers": false,
    "target": "es2015",
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": false,
      "dynamicImport": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": false,
      "react": {
        "throwIfNamespace": false,
        "useBuiltins": false,
        "pragma": "React.createElement",
        "pragmaFrag": "React.Fragment",
        "importSource": "react",
        "runtime": "automatic"
      }
    },
    "keepClassNames": false,
    "paths": {
      [REDACTED]
    },
    "baseUrl": ".."
  }
}

samsternatmiter avatar Oct 23 '25 17:10 samsternatmiter