Skip to content
This repository was archived by the owner on Aug 28, 2026. It is now read-only.
This repository was archived by the owner on Aug 28, 2026. It is now read-only.

"RangeError: Maximum call stack size exceeded" when compiling a file with many requires #689

Closed

Description

@Gobie

Do you want to request a feature or report a bug?
Bug

What is the current behavior?
Given CSS file with 10000 or more classes with URLs, in our case generated from sprites.

...
.classN { ... background-image: url(./path/to/sprite.png); ... }
...

The css-loader creates such a JS file, which on compile throws RangeError: Maximum call stack size exceeded.

...
exports.push([
  module.id, 
  ".class0 { background-image: url(" +
  escape(require("./path/to/sprite.png")) +
  "); }.class1 { background-image: url(" +
  escape(require("./path/to/sprite.png")) +
  ...
])

What is the expected behavior?
The expected behaviour is to generate a JS file, which can be compiled and executed.

Please mention other relevant information such as your webpack version, Node.js version and Operating System.
Reproducible on 0.28.10, Node 6.11.3 & Node 8.9.4.

Technical details
The issue is that URLs are replaced by requires and cssAsString in loader.js is built by string concatenation "..." + "..." + ... + "..." which has upper limit in each version of v8, given by it's default stack size.

Experimentally measured:

  • node 6.11.3 has ~6250 strings,
  • node 8.9.4 has ~3285 strings.

The fix is straightforward, group the string concatenations by fixed amount so it can be compiled using default stack size. ("..." + ... + "...") + ("..." + ... + "...")

Activity

  1. Gobie commented on Sep 17, 2018

    @Gobie
    Author
  2. alexander-akait commented on Sep 17, 2018

    @alexander-akait
    Member

    @Gobie problem still exists?

  3. Gobie commented on Sep 17, 2018

    @Gobie
    Author

    It does on 1.0.0. Test case can be found in attached commit https://github.com/Gobie/css-loader/commit/ced2c0dc24e2a0af1ea39e1d30a5d5b8e26ffb3f with "half-baked" solution.

  4. Gobie commented on Sep 17, 2018

    @Gobie
    Author

    I mistakenly closed the related pull request #690 back in July, but it is still reproducible.

  5. alexander-akait commented on Sep 17, 2018

    @alexander-akait
    Member

    @Gobie Can you create new issue with minimum reproducible test repo?

  6. Gobie commented on Sep 17, 2018

    @Gobie
    Author

    I created #771 with minimal test-case to verify that it is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions