rotemdan / lzutf8.js

A high-performance Javascript string compression library
MIT License
322 stars 26 forks source link

Node.js v5.5.0 "Range Error: Maxium call stack size exceeded" #8

Closed DoryGuy closed 8 years ago

DoryGuy commented 8 years ago

It ran fine on Node.js 0.12 but on version 5.5.0 I get the following infinite stack dump...
RangeError: Maximum call stack size exceeded at Buffer.genericArraySubarrayFunctionPolyfill as subarray at Buffer.slice (buffer.js:635:23) at Buffer.genericArraySubarrayFunctionPolyfill as subarray at Buffer.slice (buffer.js:635:23) at Buffer.genericArraySubarrayFunctionPolyfill as subarray at Buffer.slice (buffer.js:635:23)

rotemdan commented 8 years ago

Thanks for reporting. What version of the library are you using?

All array polyfills were removed on version 0.3, are you sure you're not using an earlier version?

I had a polyfill that would try to simulate a Uint8Array using a Buffer object. Since Node 3.0 it was not possible to use it anymore and thus versions of the library earlier than 0.3 cannot run on Node 3+, which uses a Uint8Array as a backing store to Buffer objects.

The errors you are seeing, if I recall correctly is the polyfill trying to override the subarray function, which before Node 3 did not exist on the Buffer object. The problem is that on Node 3+ slice now calls subarray internally, but in turn the polyfill would try to call slice and it would create an infinite loop.

Try to upgrade the library to the latest version (0.3.x) and check if you are still encountering this problem.

DoryGuy commented 8 years ago

I did a npm update lzutf8 and the header of the file lz-utf8.js is: /* LZ-UTF8 v0.2.3

Copyright (c) 2014-2015, Rotem Dan rotemdan@gmail.com Released under the MIT license.

Build date: 2015-07-18 */

rotemdan commented 8 years ago

If the package.json contains the dependency version prefixed with ^, e.g:

  "dependencies": {
    "lzutf8": "^0.2.0"
  },

Running npm update will only update up to the newest "compatible" version, in this case it was 0.2.3. You will need to either manually change the version to something like ^0.3.2, that would update to all future versions lower than 0.4.0, or *, which would always update to the latest version.

There's a guide on docs.npmjs.com

I personally use npm-check-updates instead of npm update, which always updates to the latest version regardless of the way the dependencies are listed in the package.json file (I actually wasn't aware of the "*" option until I read about it now, I'll try it as well myself).

DoryGuy commented 8 years ago

That did the trick! Thank you for all the help and the incredibly quick responses!