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.

Regex RangeError for large sourcemaps

See original GitHub issue

Hi. We’re using webpack’s devtool: #cheap-module-inline-source-map option to add an inline base64 encoded source map to the bottom of our main app file. There’s a decent amount of code there, so the sourcemap is a pretty gigantic string.

We ended up seeing the following error in the console:

RangeError: Maximum call stack size exceeded
    at RegExp.exec (native)

Related to this regex:

var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]+?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;

Changing one character in the regex fixes the issue (...[^\s'"]+?... to ...[^\s'"]*?...):

var re = /(?:\/\/[@#][ \t]+sourceMappingURL=([^\s'"]*?)[ \t]*$)|(?:\/\*[@#][ \t]+sourceMappingURL=([^\*]+?)[ \t]*(?:\*\/)[ \t]*$)/mg;

I haven’t been able to figure out why that is yet though (e.g. I don’t think there’s any catastrophic backtracking going on in the original version?) 😕

Just wondering if anyone else can shed some light on this? Cheers. (PS this change also works for the version currently published to npm).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
LinusUcommented, Jul 31, 2019

This should be fixed in version 0.5.13, please report back if the issue persists!

1reaction
SkeLLLacommented, May 31, 2017

This issue is still present. Are there any plans for fixing this?

Here’s more detailed stacktrace, if it helps:

"RangeError: Maximum call stack size exceeded"
  "at RegExp.exec (<anonymous>)",
  "at RegExp.[Symbol.match] (native)",
  "at String.match (native)",
  "at urlParse (/myproject/node_modules/source-map-support/node_modules/source-map/lib/util.js:33:20)",
  "at normalize (/myproject/node_modules/source-map-support/node_modules/source-map/lib/util.js:82:13)",
  "at Object.join (/myproject/node_modules/source-map-support/node_modules/source-map/lib/util.js:174:7)",
  "at BasicSourceMapConsumer.SourceMapConsumer_originalPositionFor [as originalPositionFor] (/myproject/node_modules/source-map-support/node_modules/source-map/lib/source-map-consumer.js:621:27)",
  "at mapSourcePosition (/myproject/node_modules/source-map-support/source-map-support.js:195:42)"
Read more comments on GitHub >

github_iconTop Results From Across the Web

3878 - RangeError running RegExp on large string - Monorail
This is working as intended. This particular regular expression requires backtracking. This means that values have to be pushed onto a stack, ...
Read more >
How to improve regex for removing source map URLs in js ...
It fails with PREG_BACKTRACK_LIMIT_ERROR = Catastrophic backtracking when the source map url is a large //# sourceMappingURL=data:application/ ...
Read more >
Writing a regex to detect a range of numbers? Why not just ...
The Regex Puzzle​​ The simplest way to solve this problem is to convert the numerical range into a regex value with every single...
Read more >
Node.js v19.3.0 Documentation
If specified, error can be a Class , RegExp , a validation function, a validation object where each property will be tested for...
Read more >
Regular expression syntax cheatsheet - JavaScript | MDN
Disjunctions are not atoms — you need to use a group to make it part of a bigger pattern. [abc] is functionally equivalent...
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