Maximum call stack size exceeded
hi, i am trying to package zigbee2mqtt, however when running:
git clone https://github.com/koenkk/zigbee2mqtt && cd zigbee2mqtt
node2nix --nodejs-10
nix-build -A package
i get the following error:
...
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/zigbee-herdsman-converters/node_modules/cli-width):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: request to https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz failed: cache mode is 'only-if-cached' but no cached response available.
npm ERR! Maximum call stack size exceeded
npm ERR! A complete log of this run can be found in:
npm ERR! /build/.npm/_logs/2020-01-28T08_24_09_521Z-debug.log
builder for '/nix/store/xm4zmgn6jfa7ql6c92wy4arx3pqqgv1j-node_zigbee2mqtt-1.9.0.drv' failed with exit code 1
error: build of '/nix/store/xm4zmgn6jfa7ql6c92wy4arx3pqqgv1j-node_zigbee2mqtt-1.9.0.drv' failed
the package.json looks like this:
{
"name": "zigbee2mqtt",
"version": "1.9.0",
"description": "Zigbee to MQTT bridge using Zigbee-herdsman",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/Koenkk/zigbee2mqtt.git"
},
"engines": {
"node": "^10 || ^12 || ^13"
},
"keywords": [
"xiaomi",
"tradfri",
"hue",
"bridge",
"zigbee",
"mqtt",
"cc2531"
],
"scripts": {
"test-with-coverage": "jest test --coverage",
"eslint": "node_modules/.bin/eslint lib/",
"start": "node index.js",
"test": "jest test",
"test-watch": "jest test --watch"
},
"author": "Koen Kanters",
"license": "GPL-3.0",
"bugs": {
"url": "https://github.com/Koenkk/zigbee2mqtt/issues"
},
"homepage": "https://koenkk.github.io/zigbee2mqtt",
"dependencies": {
"ajv": "*",
"debounce": "*",
"fast-deep-equal": "*",
"git-last-commit": "*",
"js-yaml": "*",
"mkdir-recursive": "*",
"moment": "*",
"mqtt": "*",
"object-assign-deep": "*",
"rimraf": "*",
"semver": "*",
"winston": "*",
"zigbee-herdsman": "0.12.31",
"zigbee-herdsman-converters": "11.2.8"
},
"devDependencies": {
"eslint": "*",
"eslint-config-google": "*",
"eslint-plugin-jest": "*",
"jest": "*",
"tmp": "*"
},
"jest": {
"coverageThreshold": {
"global": {
"branches": 100,
"functions": 100,
"lines": 100,
"statements": 100
}
},
"collectCoverageFrom": [
"lib/**"
]
}
}
I've uploaded the complete log at https://gist.github.com/makefu/963c3c9f6734587d7c2fcd87dc623ff0
Thanks!
This got solved by the proposed override from @juaningan , zigbee2mqtt (or one of the dependencies) requires node-gyp as buildinput (reference: https://github.com/Koenkk/zigbee2mqtt/issues/2071#issuecomment-580475938 )
sorry, need to re-open the issue. I seem to be able to make the issue disappear by running npm install before (and taining my build directory with node_packages folder).
When i remove the dependency "zigbee-herdsman" from the package.json i can finish the build (however it is obviously incomplete then).
I can also build zigbee-herdsman as only input but i am unable to run the full thing without npm crashing with npm ERR! Maximum call stack size exceeded .
Is there any workaround, like building the one big dependency seperately and merging both at the end?
Try to bump the file descriptor limit for the nix-daemon service as commented in #158
@juaningan i tried bumping the file descriptors which didn't do anything. i actually tried upping all the limits:
-t: cpu time (seconds) unlimited
-f: file size (blocks) unlimited
-d: data seg size (kbytes) unlimited
-s: stack size (kbytes) unlimited
-c: core file size (blocks) unlimited
-m: resident set size (kbytes) unlimited
-u: processes 62775
-n: file descriptors 65536
-l: locked-in-memory size (kbytes) 64
-v: address space (kbytes) unlimited
-x: file locks unlimited
-i: pending signals 62775
-q: bytes in POSIX msg queues 819200
-e: max nice 0
-r: max rt priority 0
-N 15: unlimited
Upping the stack size yielded actually yielded in another error:
...
[email protected] /nix/store/ija8r0jjbafp2jhccivlrhdp16rmggj7-node_zigbee2mqtt-1.9.0/lib/node_modules/zigbee2mqtt/node_modules/zigbee-herdsman-converters
/nix/store/qghrkvk86f9llfkcr1bxsypqbw1a4qmw-stdenv-linux/setup: line 1377: 5305 Segmentation fault (core dumped) npm --offline --nodedir=/nix/store/p02gp4kkbjiq53h7mwnwkvgpz978xagr-node-sources --production install
@juaningan which version of node2nix and zigbee2mqtt you got working?
I also tried the same package.json error, and this is the error I get:
npm ERR! cb() never called!
npm ERR! This is an error with npm itself. Please report this error at:
npm ERR! <https://npm.community>
It's a bit weird, and I have no explanation yet why this happens and under what conditions this error gets triggered. It seems that "regular" NPM users sometimes run into this as well with Node.js 10.x: https://npm.community/t/crash-npm-err-cb-never-called/858/135
I ran into the same issue in https://github.com/NixOS/nixpkgs/issues/100077 , which breaks vscode-extensions.matklad.rust-analyzer and vscode-extensions.vadimcn.vscode-lldb.
After some bisect and check, I found a minimal reproduction.
package.json (bad):
{
"name": "foo",
"version": "0.0.0",
"dependencies": {
"mocha": "=8.1.3"
}
}
Run nix run nixpkgs.nodePackages.node2nix -c node2nix && nix build -f ./. package -L
and you'll see npm ERR! Maximum call stack size exceeded.
But this works without error.
package.json (good):
{
"name": "foo",
"version": "0.0.0",
"dependencies": {
"es-abstract": "1.17.7",
"mocha": "=8.1.3"
}
}
Here's the diff of two generated node-package.nix:
diff --git a/bad.nix b/good.nix
index 7a57c94..baa7a2b 100644
--- a/bad.nix
+++ b/good.nix
@@ -1147,12 +1147,7 @@ let
sources."define-properties-1.1.3"
sources."diff-4.0.2"
sources."emoji-regex-7.0.3"
- (sources."es-abstract-1.17.7" // {
- dependencies = [
- sources."es-abstract-1.18.0-next.1"
- sources."object.assign-4.1.1"
- ];
- })
+ sources."es-abstract-1.17.7"
sources."es-array-method-boxes-properly-1.0.0"
sources."es-get-iterator-1.1.0"
sources."es-to-primitive-1.2.1"
@@ -1198,12 +1193,20 @@ let
sources."locate-path-6.0.0"
sources."log-symbols-4.0.0"
sources."minimatch-3.0.4"
- sources."mocha-8.1.3"
+ (sources."mocha-8.1.3" // {
+ dependencies = [
+ sources."object.assign-4.1.0"
+ ];
+ })
sources."ms-2.1.2"
sources."normalize-path-3.0.0"
sources."object-inspect-1.8.0"
sources."object-keys-1.1.1"
- sources."object.assign-4.1.0"
+ (sources."object.assign-4.1.1" // {
+ dependencies = [
+ sources."es-abstract-1.18.0-next.1"
+ ];
+ })
sources."once-1.4.0"
sources."p-limit-3.0.2"
sources."p-locate-5.0.0"
npm ERR! Maximum call stack size exceeded
smells like broken javascript. in nodejs, a function can take only about 100k arguments
[].push(...Array.from({ length: 1000*1000 })) // ... = spread operator
// Uncaught RangeError: Maximum call stack size exceeded
// solution:
var input = Array.from({ length: 1000*1000 }); var output = [];
for (let i = 0; i < input.length; i++) output.push(input[i]);
output.length
// 1000000
see https://github.com/sveltejs/svelte/issues/4694#issuecomment-698959034