Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DevTools failed to parse SourceMap

I am trying to get my Webpack project to have a source map file.

I finally got the settings right so that it would do that, but now I am getting this error:

DevTools failed to parse SourceMap: http://MyServer/MyApp/bundle.js.map

I go to the URL it states and I find a json file with these properties:

  • version - Set to 3
  • sources - very long array of strings that seem to be webpack paths to my files.
  • names - very long array of strings that seem to be random variables and functions.
  • mappings - very long string of seemingly random capitol letters and commas.
  • file - set to bundle.js
  • sourcesContent - Very Very long array of strings (over 10 million chars). All my source code.
  • sourceRoot - set to empty string

It all seems to be valid json. Unfortunally Chrome gives no reason why it failed to parse the source map.

Is there a way to get Chrome to say why it failed parsing the source map?

Or, failing that, does anyone know why my source map would fail? (My code is way too large to post, but here are my webpack.config.js and my package.json files.)

NOTES:

  • I have tried this with webpack 2.2.1, webpack 2.3.2 and webpack 2.6.1.
  • Source maps work fine in IE 11 and Firefox.
  • If I inline my source maps, then they work fine in Chrome DevTools, but then my bundle.js goes from 3 MB (already too big) to 16 MB (WAY too big).
  • I have set "Enable JavaScript Source Maps" in settings (and the CSS one too).
  • I tried using Chrome Canary, but it had the same issue.
  • I am hosting in IIS.
like image 417
Vaccano Avatar asked May 30 '17 16:05

Vaccano


People also ask

How do I enable SourceMap?

To enable source maps in Google Chrome, go to Developer Tools, click the little cog icon, and then make sure that “Enable Javascript source maps” is checked. That's it.

What is SourceMap URL?

The SourceMap HTTP response header links generated code to a source map, enabling the browser to reconstruct the original source and present the reconstructed original in the debugger. Header type.


2 Answers

It is not an answer to this question, but i believe my answer can help some people.

This is due to the settings of chrome, for example in FF this error warnings not happens. To fix it go to Developer Tools Settings of Chrome, and uncheck:

  1. "Enable JavaScript source maps"
  2. "Enable CSS source maps"

Then refresh Chrome.

In order to debug js and scss minified files, this tells the compiler where the source file is actually mapped.

Using last versions of Webpack source-map work well, I tried to reproduce this bug, but without possibility to run a project, i can't see what a problem of author of a question.

This warning happening for example using angular, and sourceMap should be set true in angular.json, or other way if you don't use source-map'ing' and you don't want see this warning disable it in browser following my answer.

like image 108
Arthur Tsidkilov Avatar answered Sep 21 '22 18:09

Arthur Tsidkilov


From experience, I wouldn't expect a client to tell you why it couldn't parse a SourceMap (although that would be nice). I have run into issues with some tools being unable to parse large source maps (probably memory constraints), and given your large asset size, I would look at that first.

Webpack supports several different values for the devtool config field, and some of them are less faithful than the default. Have you tried, for example, 'cheap-module-source-map'? Getting line numbers only (no columns) is a fine trade off for a usable source map IMO.

But it will probably serve you better to reduce the asset size. Webpack's code splitting and 'chunk' management options make it pretty straightforward to split your code into multiple files that are loaded async at runtime. In this case you would have two or more JS files, and each would have its own source map, so the browser will no longer choke trying to process one big file.

like image 45
Brendan Gannon Avatar answered Sep 24 '22 18:09

Brendan Gannon