hard-source-webpack-plugin
hard-source-webpack-plugin copied to clipboard
Invalid string length
Just got this error randomly after using hard-source-webpack-plugin for a few days:
RangeError: Invalid string length
at formatError (/myproject/node_modules/webpack/lib/Stats.js:221:30)
at Array.map (<anonymous>)
at Stats.toJson (/myproject/node_modules/webpack/lib/Stats.js:229:56)
at Compiler.<anonymous> (/myproject/node_modules/html-webpack-plugin/index.js:68:44)
at Compiler.applyPluginsAsyncSeries (/myproject/node_modules/tapable/lib/Tapable.js:206:13)
at Compiler.emitAssets (/myproject/node_modules/webpack/lib/Compiler.js:354:8)
at onCompiled (/myproject/node_modules/webpack/lib/Compiler.js:58:19)
at applyPluginsAsync.err (/myproject/node_modules/webpack/lib/Compiler.js:510:14)
at next (/myproject/node_modules/tapable/lib/Tapable.js:202:11)
at Compiler.<anonymous> (/myproject/node_modules/webpack/lib/CachePlugin.js:78:5)
at next (/myproject/node_modules/tapable/lib/Tapable.js:204:14)
at /myproject/node_modules/hard-source-webpack-plugin/index.js:2062:7
at <anonymous>
We have started experiencing the exact same issue. The "Invalid string length" error seems to actually mean that node ran out of memory.
Broad overview of our setup: Webpack (^3.11.0), Awesome TS-loader (^4.0.1), React (^16.3.2)
Here's what we've found so far:
- The error tends to not appear on an initial build with webpack, but primarily after saving changes when running webpack in watch mode.
- The error does not always occur, but about 70% of the time
- The error appears at the very end of webpack's bundling step: Asset optimization
- Webpack is stuck on "Asset optimization" for about 30 seconds before the error appears.
Can confirm
"react": "^15.3.2",
"hard-source-webpack-plugin": "^0.5.18",
"webpack": "^3.10.0",
@pawelkondraciuk @DerJacques Are you getting the EXACT SAME error? This is a common symptom for hard-source but with an endless number of causes from other plugins, loaders, es2015 module syntax in specific npm packages, etc. If you have a different error please open a separate issue.
If you're getting the same issue, if any of you can create a reproduction project that would be really helpful.
TLDR of the symptom, something being stringified is trying to make a string larger than ~130MB (javascript implementation detail for node/v8). A previous example of the bug was webpack dependencies that created a tree that refered to each non-recursively to the point that what was <1MB in memory grew past the string limit when stringified because stringifing doesn't remove duplicate memory values.
The example I'm mentioning was caused by a deeply nested npm dependency in another user's project. Its hard to find the causes for this symptom without a reproduction project.