oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.48k stars 2.71k forks source link

ESM import/export errors stacktrace lack the filenames that led to the error #7700

Open peacefulotter opened 9 months ago

peacefulotter commented 9 months ago

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

Linux 6.2.0-37-generic x86_64 x86_64

What steps can reproduce the bug?

Inside your project, use a symlink or use npm i -S ../other-project/. Import the "other-project" and throw an error in it.

What is the expected behavior?

The stacktrace resolves and shows the proper paths.

What do you see instead?

Bun will print a stacktrace where the paths of the stacktrace just say a bunch of link. Example:

1 | (function (entry, fetcher)
                        ^
SyntaxError: Export named '...' not found in module 'other-project/src/index.ts'.
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at link (:1:21)
      at linkAndEvaluateModule (:1:21)
      at processTicksAndRejections (:61:77)

Not only it just prints a bunch of links, but, even without symlinks, I have encountered many times a stack trace that will just print the error and only then contain the processTicksAndRejections without anything else - not very useful.

Additional information

No response

peacefulotter commented 9 months ago

@Jarred-Sumner As discussed on discord, here is the issue! :)

peacefulotter commented 9 months ago

Reviving this issue as this is still relevant and, imo, important

Jarred-Sumner commented 9 months ago

For any contributors

I think the way to fix this is to add a throwResolutionError lambda in here, which would call createSyntaxError but add a dependencies or dependents array of keys

https://github.com/oven-sh/WebKit/blob/b4de09f41b83e9e5c0e43ef414f1aee5968b6f7c/Source/JavaScriptCore/runtime/JSModuleRecord.cpp#L184-L234

I do wonder if there's some way to make this work via interpreter

maxime-aubry commented 2 months ago

I have the same bug today. How can i fix it ?