paixaop / node-sodium

Port of the lib sodium encryption library to Node.js
MIT License
351 stars 126 forks source link

Invalid ELF Header #149

Closed ZacharyDraper closed 5 years ago

ZacharyDraper commented 5 years ago

Looking for a little help here. I am trying to run our node.js app on Debian. npm install works fine and the app starts, but as soon as we try to decrypt something with Sodium we get the following error:

Error: /home/node/node_modules/sodium/build/Release/sodium.node: invalid ELF header
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:775:18)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)
    at Module.require (internal/modules/cjs/loader.js:663:17)
    at require (internal/modules/cjs/helpers.js:20:18)
    at Object.<anonymous> (/home/node/node_modules/sodium/lib/sodium.js:16:15)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)

'invalid ELF header' apparently has something to do with the file extension. Not really sure. https://stackoverflow.com/questions/40312319/invalid-elf-header-out-of-the-gate-running-simple-nodejs-script?rq=1

Looking for some guidance on where to look next.

ZacharyDraper commented 5 years ago

I figured this out and it isn't node-sodium itself. When building a Dockerfile, using a volume can be a problem. If you need a volume, make sure node_modules isn't in it. There are a bunch of resources on this. Here is one as an example:

https://jdlm.info/articles/2016/03/06/lessons-building-node-app-docker.html#the-node_modules-volume-trick