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

dlopen failed: "/node_modules/osrm/lib/binding/node_osrm.node" has bad ELF magic

Open andreddosantos opened this issue 3 years ago • 1 comments

Hello we're building an hybrid mobile app using ionic with cordova that uses offline maps. We would like to add an offline routing engine to calculate offline routes. Our app uses a nodejs backend on the phone for some functionalities and we also would like to include the osrm package into our nodejs mobile server.

We know its possible to use osrm in mobile for offline routing, since the app maps.me used to use it, and also as referred on this issue.

Our current error:

The app compiles successfully, but when trying to start the osrm library it breaks

 var OSRM = require('osrm');

Error:

Error: dlopen failed: "/data/data/io.xxx.map/files/www/nodejs-project/node_modules/osrm/lib/binding/node_osrm.node" has bad ELF magic: cffaedfe
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1183:18)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
    at require (internal/modules/cjs/helpers.js:77:18)
    at Object.<anonymous> (/data/data/io.xxx.map/files/www/nodejs-project/node_modules/osrm/lib/index.js:1:29)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)

Hope you can help, Kind regards André

andreddosantos avatar Mar 11 '21 17:03 andreddosantos

OSRM is implemented in NodeJS as a binary loadable module. When you do npm install, it downloads the appropriate binary module for the platform on which npm is being executed (i.e. your local machine, your build machine).

If you've created a local build of your app, packed up the artifacts, then shipped them to a mobile device with a different architecture, you'll have the wrong OSRM binary module for that platform. The has bad ELF magic: cffaedfe indicates that Linux (I assume you're deploying to Android) doesn't recognize the format of the node_osrm.node file that you've bundled.

I don't know if we pre-publish the right binaries for your platform. You should try running npm install from within your Android environment to see if it is able to fetch a working OSRM binary file.

danpat avatar Mar 11 '21 17:03 danpat