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

RangeError: Maximum call stack size exceeded (problematic regexp for long in line source maps) #49

Open
doctorpangloss opened this issue Jan 20, 2024 · 1 comment

Comments

@doctorpangloss
Copy link

doctorpangloss commented Jan 20, 2024

We work on a large application, and next.js transitively uses this package for inline source maps.

The regexp used to detect the contents of the source maps starts to choke on inline source maps created for Emscripten-generated loader Javascript.

RangeError: Maximum call stack size exceeded
    at RegExp.exec (<anonymous>)
    at retrieveSourceMapURL (C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:340:21)
    at Array.<anonymous> (C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:353:26)
    at C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:199:32
    at mapSourcePosition (C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:383:21)
    at wrapCallSite (C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:592:20)
    at Function.prepareStackTrace (C:\Users\bberman\Documents\appmana\node_modules\@cspotcode\source-map-support\source-map-support.js:671:41)
    at maybeOverridePrepareStackTrace (node:internal/errors:142:29)
    at prepareStackTrace (node:internal/errors:116:5)
    at getStackString (node:internal/util/inspect:1240:16)
    at formatError (node:internal/util/inspect:1369:15)
    at formatRaw (node:internal/util/inspect:985:14)
    at formatValue (node:internal/util/inspect:840:10)
    at inspect (node:internal/util/inspect:364:10)
    at formatWithOptionsInternal (node:internal/util/inspect:2298:40)

This is actually a very painful error. I am hoping you can deal with the data URI-style values on the right hand side of the source map marker potentially without using a regular expression to find the right hand side.

@doctorpangloss doctorpangloss changed the title RangeError: Maximum call stack size exceeded RangeError: Maximum call stack size exceeded (problematic source maps for long single lines) Jan 20, 2024
@doctorpangloss doctorpangloss changed the title RangeError: Maximum call stack size exceeded (problematic source maps for long single lines) RangeError: Maximum call stack size exceeded (problematic regexp for long in line source maps) Jan 20, 2024
@hydrosquall
Copy link

hydrosquall commented Aug 15, 2024

As a workaround in the build system for a Storybook build system (using webpack with babel rather than SWC), I temporarily disabled sourcemaps when working with these large files. This package is used by babel-core .

These are the lines with the expensive regexp :

fileData = retrieveFile(tryFileURLToPath(source));
var re = /(?:\/\/[@#][\s]*sourceMappingURL=([^\s'"]+)[\s]*$)|(?:\/\*[@#][\s]*sourceMappingURL=([^\s*'"]+)[\s]*(?:\*\/)[\s]*$)/mg;
// Keep executing the search to find the *last* sourceMappingURL to avoid
// picking up sourceMappingURLs from comments, strings, etc.
var lastMatch, match;
while (match = re.exec(fileData)) lastMatch = match;
if (!lastMatch) return null;
return lastMatch[1];

I noticed postcss faced a similar RangeError while looking for SourceMaps in their project . Perhaps a similar RegEx simplification could work for node source-map-support too.

postcss/postcss@164eb37

postcss/postcss#1646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants