I'm using AWS Lambda, which involves creating an archive of my node.js script, including the node_modules
folder and uploading that to their infrastructure to run.
This works fine, except when it comes to node modules with native bindings (using node-gyp). Because the binding was complied and project archived on my local computer (OS X), it is not compatible with AWS's (Amazon Linux) servers.
How can I cross-compile/install a node module (specifically, node-sqlite3) so when I upload it to another server arch it runs?
While not really a solution to your problem, a very easy workaround could be to simply compile the native addons on a Linux machine.
For your particular situation, I would use Vagrant. Vagrant can create virtual machines and configure them within seconds.
yum
as package manager - see Wiki)npm install
(optionally it might also remove the node_modules folder before to ensure a clean installation)It might require some tuning if the linked libraries are not at the same place on the target machine but generally this seems to me like the best and quickest solution.