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

Broken sourcemap in the stack trace of uncaught errors #447

Closed
4 of 6 tasks
unleashy opened this issue Dec 27, 2023 · 7 comments
Closed
4 of 6 tasks

Broken sourcemap in the stack trace of uncaught errors #447

unleashy opened this issue Dec 27, 2023 · 7 comments

Comments

@unleashy
Copy link

unleashy commented Dec 27, 2023

Acknowledgements

  • I searched existing issues before opening this one to avoid duplicates
  • I understand this is not a place for seek help, but to report a bug
  • I understand that the bug must be proven first with a minimal reproduction
  • I will be polite, respectful, and considerate of people's time and effort

Minimal reproduction URL

https://gist.github.com/unleashy/6b0956eb7572cafbf0eb5f18c9c491a4

Version

v4.7.0

Node.js version

v20.10.0

Package manager

N/A

Operating system

Windows

Problem & Expected behavior

Run npx tsx foo.ts with the code from the gist:

file:///C:/Programming/js/foo.ts:1
let foo="foo";throw new Error("foo");
                    ^

Error: foo
    at <anonymous> (c:\Programming\js\foo.ts:4:7)
    at ModuleJob.run (node:internal/modules/esm/module_job:218:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:329:24)
    at async loadESM (node:internal/process/esm_loader:34:7)
    at async handleMainPromise (node:internal/modules/run_main:113:12)

Node.js v20.10.0

Basically if an uncaught error is displayed, as per normal node procedure the line of the code where the error was thrown is shown, in the original sourcemap. However tsx dumps the whole contents of the file, minified, into the console. For small files, as in the reproduction, I guess this is fine? But for big files the console gets utterly spammed with completely useless minified code. Curiously, the file paths are correct.

I couldn't get to reproduce this on Stackblitz… so I'm guessing this is some sort of Windows problem? But it doesn't happen with ts-node.

I tested with npm and yarn and both had the same result. And whatever is in tsconfig.json seems to make no difference.

The expected behaviour for me would be for the code displayed in the error trace to only show the line of the affected code, source-mapped to the original Typescript.

Contributions

  • I plan to open a pull request for this issue
  • I plan to make a financial contribution to this project
@unleashy unleashy added bug Something isn't working pending triage labels Dec 27, 2023
@unleashy unleashy changed the title Broken sourcemap for uncaught error stacks Broken sourcemap in the stack trace of uncaught errors Dec 27, 2023
@wydengyre

This comment was marked as duplicate.

@wydengyre
Copy link

@unleashy Not just a Windows problem. Same bug for me on MacOS (14.3.1).

@privatenumber
Copy link
Owner

Thanks for reporting—happy to accept a PR to fix this!

Locking thread to direct further dialogue in the form of PRs.

Repository owner locked and limited conversation to collaborators Feb 28, 2024
Repository owner unlocked this conversation Apr 4, 2024
@privatenumber
Copy link
Owner

@wydengyre

I believe you were experiencing #478 which was fixed in v4.7.2
I'm guessing most people stumbling across this thread may be confusing this with that too.

@unleashy

Your problem is happening in Node v20.10.0, which means it's not related to #478

I don't have a Windows but it works fine for me on Mac.
Can you provide a reproduction via GitHub Actions CI using a Windows OS?

@privatenumber
Copy link
Owner

Closing as a reproduction was not provided

@privatenumber privatenumber closed this as not planned Won't fix, can't repro, duplicate, stale May 4, 2024
@mistaecko
Copy link

@privatenumber
I can reproduce on OSX using the steps below. Note that I was not able to reproduce with the OP's example.

nvm use 20
mkdir tsx-issue447 && cd tsx-issue447
npx cdk init app --language typescript
sed -i.bak 's/\/\/ The code.*$/throw new Error("Duh!");/' lib/tsx-issue447-stack.ts
npx tsx bin/tsx-issue447.ts

Output - notice that the file is correct, but location is 2:1366

Error: Duh!
    at new TsxIssue447Stack (/Users/me/tsx-issue447/lib/tsx-issue447-stack.ts:2:1366)
    at /Users/me/tsx-issue447/bin/tsx-issue447.ts:3:950
    at Object.<anonymous> (/Users/me/tsx-issue447/bin/tsx-issue447.ts:4:3)

@privatenumber
Copy link
Owner

@mistaecko

Thanks, I can reproduce the error with that, but I don't think this is related to what @unleashy reported.

@unleashy's reproduction allegedly errored with a single file.

In your case, the issue comes from import 'source-map-support/register' interfering with the stack trace. source-map-support is an unmaintained package superseded by Node's native source maps: https://nodejs.org/api/cli.html#--enable-source-maps

I'm still interested in the original issue @unleashy is reporting, but I'm going to lock this thread to prevent piling on since it's happened twice already.

Repository owner locked and limited conversation to collaborators May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants