question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use better-suited devtool option for sourcemaps

See original GitHub issue

I recently hit an issue where this value was showing up as undefined when debugging in browser’s dev tools, in cases like this:

const foo = {
  greeting: "hello",
  audiences: ["world", "mars", "wales"],

  bar() {
    return this.audiences.map(audience => {
      return `${this.greeting} ${audience}`; // `this` is `undefined` when inspecting
    });
  }
};

Note, this is only when debugging and inspecting the value (e.g. mouseover), the actual code is fine when running.

After some research I realised this was due to the choice to sourcemap generated by webpack. You currently have it set to "cheap-module-source-map", which the webpack docs say is "not ideal for development nor production".

The webpack docs recommend either "eval", "eval-source-map", "cheap-eval-source-map", or "cheap-module-eval-source-map"for dev. "eval-source-map" fixed the issue I described above.

Is it worth changing to a setting recommended by webpack, or is there some specific reason for using "cheap-module-source-map" that is not obvious to me?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
WickyNilliamscommented, Nov 23, 2017

Right now, breakpoints seem to be working fine for me in chrome with eval-source-map. I’ll report back at the end of the day after using it for a few hours.

Source maps support mapping of variable/symbol names. I assume only the more comprehensive sourcemap generation options do this, whereas the more lightweight options do not. See https://bugs.chromium.org/p/chromium/issues/detail?id=327092

In any case, the current choice is not recommended so it’s probably worth changing to one that is recommended, even if it is not eval-source-map

2reactions
jasonLastercommented, Aug 24, 2018

We recently landed support for mapping scopes and variables in Firefox DevTools. The feature requires column-based mappings, which are needed for accurately mapping identifiers between original and generated code.

Webpack has a couple of source map options that work well (source-map, eval-source-map , inline-source-map). Basically it can’t be cheap (read line-based) and it has to include the original source docs.

Would you be open to switching from a cheap-module-source-map to one of the other options in development?

Before

screen shot 2018-08-24 at 6 32 01 pm

After

image
Read more comments on GitHub >

github_iconTop Results From Across the Web

Devtool - webpack
devtool performance production quality (none) build: fastest rebuild: fastest yes bundle eval build: fast rebuild: fastest no generated eval‑cheap‑source‑map build: ok rebuild: fast no transformed
Read more >
Quick guide to webpack source map options - Scott Logic Blog
A quick guide to the available source map options in webpack, and the considerations for choosing one in different scenarios.
Read more >
Source Maps - SurviveJS
devtool : "source-map" is the highest quality option valuable for production. inline-module-source-map is a good starting point for development. Use devtool: " ...
Read more >
Source maps and how it works - Ehsan Gazar
Using Webpack, specifying devtool: "source-map" in your Webpack ... eval-source-map is the highest quality option of the inline options.
Read more >
Webpack - devtool source-map VS eval-source-map
The webpack docs have a handy chart about which cases these different options may be suited for though. They show eval-source-map as being ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found