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

Consume source maps from JavaScript files #4499

Open
kitsonk opened this issue Mar 27, 2020 · 4 comments
Open

Consume source maps from JavaScript files #4499

kitsonk opened this issue Mar 27, 2020 · 4 comments
Assignees
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted)

Comments

@kitsonk
Copy link
Contributor

kitsonk commented Mar 27, 2020

Current Deno will remap stack traces on files that have been compiled by Deno, as Deno caches both the original file and the emitted map, and loads those from the cache. When consuming JavaScript with source maps from other sources (like already compiled code) Deno does not handle the source map and ignore source map pragma included in files.

Deno should support both external source maps and inline source maps when fetching modules and store any source maps in the cache to be used when remapping stack traces.

This will have the side-effect of supporting the generation of source maps for bundles generated by deno bundle.

One consideration is that source maps optionally can include the original sources. If they do, then when emitting an error, the original source line is available, but if they don't, we would not be able to log-out/resolve that original source line.

@ry ry added the feat new feature (which has been agreed to/accepted) label Mar 30, 2020
@kitsonk kitsonk mentioned this issue Mar 31, 2020
18 tasks
@kitsonk kitsonk added the cli related to cli/ dir label Nov 5, 2020
@kitsonk kitsonk self-assigned this Nov 5, 2020
@bartlomieju bartlomieju mentioned this issue Dec 18, 2020
22 tasks
@kitsonk kitsonk added this to the 1.21 milestone Apr 1, 2022
@kitsonk kitsonk modified the milestones: 1.21, 1.22 Apr 25, 2022
@lucacasonato lucacasonato removed this from the 1.22 milestone Sep 28, 2023
@71
Copy link

71 commented Dec 9, 2023

Several issues referring to inline source maps were closed as duplicates of this one, but this also applies to linked source maps:

function fail() {
  throw new Error("failed");
}

fail();

Build with esbuild:

$ esbuild repro.ts --minify --sourcemap=linked --outfile=repro.js

With Node and source-map-support:

$ node -r source-map-support/register repro.js
file:///repro.ts:2
  throw new Error("failed");
        ^
Error: failed
    at fail (file:///repro.ts:2:9)
    at file:///repro.ts:5:1
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

With Deno:

$ deno run repro.js
error: Uncaught Error: failed
"use strict";function fail(){throw new Error("failed")}fail();
                                   ^
    at fail (file:///repro.js:1:36)
    at file:///repro.js:1:56

@skovsboll
Copy link

I would love better source maps support. Useful for debugging unit tests.

@scarf005
Copy link
Contributor

scarf005 commented Jun 2, 2024

they would be really useful, currently go to source definition feature doesn't work in esm.sh due to deno being unable to handle source maps.

@bartlomieju
Copy link
Member

This needs to be redesigned and implemented in deno_core.

The problem is that we have our own system of handling source maps and not using the built-in V8 APIs that Luca mentions here.

We currently have a SourceMapGetter trait that needs to implement a couple methods to retrieve a source map.

Arguably, we should remove that trait and instead move these methods to ModuleLoader trait since most implementors will make their module loader a source map getter anyway. Then the logic in deno_core needs to change to first look up module in the ModuleMap and using V8 APIs check if the source map is embedded in the code or uses a URL to link to a source map. Only in the latter case we should delegate to the ModuleLoader to fetch us a source map from provided URL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli related to cli/ dir feat new feature (which has been agreed to/accepted)
Projects
None yet
Development

No branches or pull requests

7 participants