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

Error-stacktrace are wrong when using ts-node + source-map-support #1440

Closed
stavalfi opened this issue Aug 22, 2021 · 7 comments
Closed

Error-stacktrace are wrong when using ts-node + source-map-support #1440

stavalfi opened this issue Aug 22, 2021 · 7 comments
Milestone

Comments

@stavalfi
Copy link

When I downgrade to ts-node 9.1.1 all works great (or run my code without ts-node I get the correct javascript stacktraces).

Expected Behavior

correct error-stacktraces

Actual Behavior

Steps to reproduce the problem

Minimal reproduction

I can't share my code because it's private.
I couldn't reproduce this bug easily in a minimal example.

Specifications

ts-node v10.2.1
node v14.15.4
compiler v4.1.3
  • ts-node version:
  • node version:
  • TypeScript version:
  • tsconfig.json, if you're using one:
{
  "compilerOptions": {
    "noImplicitAny": false,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "declaration": true,
    "allowSyntheticDefaultImports": true,
    "sourceMap": true,
    "strict": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "target": "ES2019",
    "lib": ["esnext", "DOM", "DOM.Iterable"],
    "preserveSymlinks": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "composite": true,
    "baseUrl": "packages",
    "paths": {
      "@singer/common": ["common/src/index.ts"],
      "@singer/test-infra": ["tests-infra/src/index.ts"]
    },
    "resolveJsonModule": true,
    "jsx": "react"
  }
}
  • Operating system and version: macos big sur 11.5.2
@stavalfi stavalfi changed the title error-stacktrace are wrong when using ts-node + source-map-support Error-stacktrace are wrong when using ts-node + source-map-support Aug 22, 2021
@cspotcode
Copy link
Collaborator

Probably a duplicate of #1438

@stavalfi
Copy link
Author

I will update if it helped. Thanks.

@stavalfi
Copy link
Author

stavalfi commented Aug 24, 2021

Update:

After upgrading to:

"@cspotcode/source-map-support": "0.6.1",
"ts-node":"10.2.1"

All works great.

Thanks!

@cspotcode
Copy link
Collaborator

You may able to remove the @cspotcode/source-map-support dependency entirely, since ts-node already registers it.

@stavalfi
Copy link
Author

You may able to remove the @cspotcode/source-map-support dependency entirely, since ts-node already registers it.

In production I run js files directly with node so i must register it manually.
as it's best practice to declare the deps im using directly and yarn2/pnpm wont let me use it without declaring it, then I must :P

@fox1t
Copy link

fox1t commented Oct 7, 2021

I am experiencing the same issue on ts-node v10.2.1. Downgrading to v9.1.1 works like expected. I am using node-tap that uses ts-node internally to run .ts and .tsx tests. After digging a bit, I found this is a ts-node source map support issue.

Dummy repro

import { test } from 'tap'

test('lol', async t => {
  t.test('lol1', async t2 => {
    t2.pass()
  })
  t.test('lol2', async t2 => {
    t2.pass()
  })
  t.test('lol3', async t2 => {
    t2.equal(1, 2)
  })
})

On v10.2.1 the stack trace is printed like:

  57 | test('lol', async t => {
  58 |   t.test('lol1', async t2 => {
> 59 |     t2.pass()
     | -----------^
  60 |   })
  61 |   t.test('lol2', async t2 => {
  62 |     t2.pass()

On the other hand, on v9.1.1 the trace is:

  63 |   })
  64 |   t.test('lol3', async t2 => {
> 65 |     t2.equal(1, 2)
     | -------^
  66 |   })
  67 | })

Any suggestion about how to fix this?

note: this might be related to https://github.com/tapjs/node-tap/blob/23c7821213b44e2f85579ea5a244cd4c6ffe35df/settings.js#L6
note2: setting @cspotcode/source-map-support in this line https://github.com/tapjs/node-tap/blob/main/settings.js#L3 fixes the issue.

I was able to fix this issue adding a custom settings to node-tap, that uses @cspotcode/source-map-support instead of source-map-support:
https://github.com/fox1t/typescript-microservice-starter/blob/master/libtap-settings.js

@cspotcode cspotcode added this to the 10.3.0 milestone Oct 11, 2021
@cspotcode
Copy link
Collaborator

A workaround for this has been published in v10.3.0

https://github.com/TypeStrong/ts-node/releases/tag/v10.3.0

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