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

1:many sourcemaps - Cannot read property 'source' of undefined #132

Open
tomardern opened this issue Jan 31, 2021 · 0 comments
Open

1:many sourcemaps - Cannot read property 'source' of undefined #132

tomardern opened this issue Jan 31, 2021 · 0 comments
Labels

Comments

@tomardern
Copy link

tomardern commented Jan 31, 2021

Hi,

I'm getting a Cannot read property 'source' of undefined error when trying to process a file compressed.min.js which has the following compressed.js.map. All the sources are in the same directory.

{
  "version": 3,
  "file": "compressed.min.js",
  "sources": [
    "widget.js",
    "plugin.js",
    "app.js"
  ],
  "names": [
    "Widget",
    "console",
    "log",
    "Plugin",
    "window",
    "onload"
  ],
  "sourceRoot": "/project/",
  "mappings": "AAAA,GAAIA,QAAS,WAGX,GAAIA,GAAS,WACXC,QAAQC,IAAI,yBAId,OAAOF,MCRLG,OAAS,WAGX,GAAIA,GAAS,WACXF,QAAQC,IAAI,yBAId,OAAOC,KCRTC,QAAOC,OAAS,WACfJ,QAAQC,IAAI,wCAEC,IAAIF,QAEJ,GAAIG"
}

Full Error below:

(node:79066) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'source' of undefined
    at V8ToIstanbul._maybeRemapStartColEndCol (/project/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:188:40)
    at /project/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:110:60
    at Array.forEach (<anonymous>)
    at /project/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:109:20
    at Array.forEach (<anonymous>)
    at V8ToIstanbul.applyCoverage (/project/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:108:12)

However, if I include the "sourcesContent", for example:

{
  "version": 3,
  "file": "compressed.min.js",
  "sources": [
    "widget.js",
    "plugin.js",
    "app.js"
  ],
  "names": [
    "Widget",
    "console",
    "log",
    "Plugin",
    "window",
    "onload"
  ],
  "sourcesContent": [
    "var Widget = (function () {\n  // Constructor\n  var Widget = function () {\n    console.log(\"Logged from widget.js\");\n  };\n\n  // Export Widget.\n  return Widget;\n})();",
    "var Plugin = (function () {\n  // Constructor\n  var Plugin = function () {\n    console.log(\"Logged from plugin.js\");\n  };\n\n  // Export Plugin.\n  return Plugin;\n})();",
    "window.onload = function () {\n  console.log(\"This was logged from the app.js file.\");\n\n  var widget = new Widget();\n\n  var plugin = new Plugin();\n};"
  ],
  "mappings": "AAAA,GAAIA,QAAS,WAGX,GAAIA,GAAS,WACXC,QAAQC,IAAI,yBAId,OAAOF,MCRLG,OAAS,WAGX,GAAIA,GAAS,WACXF,QAAQC,IAAI,yBAId,OAAOC,KCRTC,QAAOC,OAAS,WACfJ,QAAQC,IAAI,wCAEC,IAAIF,QAEJ,GAAIG"
}

Then the instanbul report is generated successfully.


The following also works:

const map = JSON.parse(fs.readFileSync("compressed.js.map"));
map.sourcesContent = map.sources.map((f) =>fs.readFileSync(f, "utf-8"));

const converter = v8toIstanbul("compressed.min.js", undefined, {
  sourceMap: { sourcemap: map },
});
return converter.load().then((c) => {
  converter.applyCoverage(v8Coverage);
  console.info(JSON.stringify(converter.toIstanbul()));
});

After some debugging:

If I change the following line (https://github.com/istanbuljs/v8-to-istanbul/blob/master/lib/v8-to-istanbul.js#L51)

...
 if (this.rawSourceMap.sourcemap.sources.length > 1) {
        this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap)
   ...

to false, so that it fetches the files from disk, then it all seems ok :)

...
if (false) {
       this.sourceMap = await new SourceMapConsumer(this.rawSourceMap.sourcemap)
  ...

Potentially the this.rawSourceMap.sourcemap.sources.length > 1 should also check that sourcesContent is defined for each of the sources?

Thanks!

hkollmann added a commit to qooxdoo/qxl.testtapper that referenced this issue Feb 3, 2021
support for coverage will follow after this istanbuljs/v8-to-istanbul#132 is solved
@bcoe bcoe added the bug label Feb 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants