node-rdkafka icon indicating copy to clipboard operation
node-rdkafka copied to clipboard

Confusing macOS pre-compiled node-librdkafka.node in packaged releases

Open mlazzarini opened this issue 9 years ago • 7 comments

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:carbon in 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:

  • node v. 8.9.0
  • node-rdkafka v. 2.1.1

mlazzarini avatar Nov 21 '17 10:11 mlazzarini

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.

mlazzarini avatar Nov 22 '17 16:11 mlazzarini

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".

ankon avatar Nov 22 '17 16:11 ankon

That file should not be published with the library. I'll investigate.

webmakersteve avatar Nov 27 '17 17:11 webmakersteve

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

lovedebug avatar Dec 26 '17 03:12 lovedebug

Is there any work around available for this issue?

prakashkumars avatar Jan 05 '18 00:01 prakashkumars

+1

tiggerk avatar Jan 07 '18 14:01 tiggerk

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.

webmakersteve avatar Jan 08 '18 18:01 webmakersteve