sindresorhus / clean-stack

Clean up error stack traces
MIT License
337 stars 29 forks source link

Normalize file URLs to paths? #27

Closed silverwind closed 3 years ago

silverwind commented 3 years ago

Node 16 uses file:// URLs in stack traces, I wonder whether this module should attempt to normalize these to file system paths using fileURLToPath to shorten the output and keep it consistent with previous node versions.

Error: Some error message
    at myFunction (file:///path/to/file.js:356:45)
    at Array.map (<anonymous>)
    at myOtherFunction (file:///path/to/file.js:386:45)
    at runMicrotasks (<anonymous>)

Not directly related but runMicrotasks seems also something this module could hide.

sindresorhus commented 3 years ago

Do you know why they changed it? Normal paths would look better and also be Command-clickable in many terminals. Maybe worth opening an issue on Node.js on this first?

bmeck commented 3 years ago

@sindresorhus those URLs show up in ESM based modules since ESM doesn't necessarily come from a file; CJS only uses file paths to define their location when telling V8 where the source text lives, but full URLs are used for ESM so V8 shows the full URL in Error stacks.

silverwind commented 3 years ago

I guess it's fine to leave the file URLs, it's closer to browser APIs and I see a general movement towards URLs for filesystem operations in the ecosystem too, reinforced by the ESM loader dealing only with URLs itself.