Confusing macOS pre-compiled node-librdkafka.node in packaged releases
Trying to run my NodeJS application which is using node-rdkafka library, it crashes.
I've tried different docker base images, and I get different errors:
- with
FROM node:carbonin my Dockerfile, I get:
/app/node_modules/bindings/bindings.js:88
throw e
^
Error: /app/node_modules/node-rdkafka/build/Release/node-librdkafka.node: invalid ELF header
at Object.Module._extensions..node (module.js:664:18)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at bindings (/app/node_modules/bindings/bindings.js:81:44)
at Object.<anonymous> (/app/node_modules/node-rdkafka/librdkafka.js:10:32)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
- with
FROM node:boron, I get:
/app/node_modules/bindings/bindings.js:88
throw e
^
Error: /app/node_modules/node-rdkafka/build/Release/node-librdkafka.node: invalid ELF header
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at bindings (/app/node_modules/bindings/bindings.js:81:44)
at Object.<anonymous> (/app/node_modules/node-rdkafka/librdkafka.js:10:32)
at Module._compile (module.js:570:32)
- with
FROM node:carbon-alpine, I get:
/app/node_modules/bindings/bindings.js:88
throw e
^
Error: Error loading shared library /app/node_modules/node-rdkafka/build/Release/node-librdkafka.node: Exec format error
at Object.Module._extensions..node (module.js:664:18)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Module.require (module.js:579:17)
at require (internal/module.js:11:18)
at bindings (/app/node_modules/bindings/bindings.js:81:44)
at Object.<anonymous> (/app/node_modules/node-rdkafka/librdkafka.js:10:32)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
I'm using:
nodev. 8.9.0node-rdkafkav. 2.1.1
In addition: the corrupted binary file /app/node_modules/node-rdkafka/build/Release/node-librdkafka.node is already included when downloading node-rdkafka from npm registry. That's wrong, as the operating system is trying to load it as a library and fails. It should be removed.
We found the underlying cause of the problem now: Our build process only executed npm install --ignore-scripts on the target system (i.e. the docker image @mlazzarini described), and so we ended up with whatever node-librdkafka.node was installed through that: a Mach-O 64-bit x86_64 bundle, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|WEAK_DEFINES|BINDS_TO_WEAK|HAS_TLV_DESCRIPTORS>
This binary would only ever be useful for people using exactly the same architecture and NodeJS version as whoever compiled that. Initially we got rather confused by the error message, which pointed to "build is compiling the wrong thing" and not "build isn't compiling at all".
That file should not be published with the library. I'll investigate.
same issue when i zip my project with all node modules from macos to centos. macos run node 8.9.1, centos run node 8.9.3
Is there any work around available for this issue?
+1
This issue has been fixed in a previous build. The build directory is now in .npmignore
https://github.com/Blizzard/node-rdkafka/commit/5da5199ff4fe1690a3f4327b2892bf42a2fd75a7
Just verified by running npm install --ignore-scripts. If you folks are having the same issue please open a new github issue with details.