使用node-gyp与本机绑定交叉编译节点模块 [英] Cross-compile node module with native bindings with node-gyp

查看:304
本文介绍了使用node-gyp与本机绑定交叉编译节点模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS Lambda,这涉及到创建我的node.js脚本的存档,包括node_modules文件夹并将其上传到其基础架构上运行.

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.

这很好用,除非涉及带有本机绑定的节点模块(使用node-gyp).由于绑定是在我的本地计算机(OS X)上完成的,并且已将项目存档,因此它与AWS的(Amazon Linux)服务器不兼容.

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.

如何交叉编译/安装节点模块(特别是 node-sqlite3 )所以当我将其上传到另一个服务器架构时,它会运行吗?

How can I cross-compile/install a node module (specifically, node-sqlite3) so when I upload it to another server arch it runs?

推荐答案

虽然不是您问题的真正解决方案,但一种非常简单的解决方法是仅在Linux机器上编译本机插件.

While not really a solution to your problem, a very easy workaround could be to simply compile the native addons on a Linux machine.

对于您的特定情况,我会使用 Vagrant . Vagrant可以创建虚拟机并在几秒钟内对其进行配置.

For your particular situation, I would use Vagrant. Vagrant can create virtual machines and configure them within seconds.

  1. 查找类似于Amazon Linux发行版的OS映像(Fedora,CentOS,以及其他使用yum作为程序包管理器的映像)-请参见 Wiki )
  2. 使用一个简单的配置脚本,该脚本在Vagrant在计算机启动时运行时将运行npm install(可选地,它可能还会在确保全新安装之前删除 node_modules 文件夹)
  3. 为了更加舒适,脚本还可以创建用于部署的zip文件
  4. 安装完成后,脚本将关闭VM,以避免不必要的系统资源消耗
  5. 部署!
  1. Find an OS image that resembles Amazon's Linux distro (Fedora, CentOS, others that use yum as package manager - see Wiki)
  2. Use a simple configuration script that, when run by Vagrant on machine startup, will run npm install (optionally it might also remove the node_modules folder before to ensure a clean installation)
  3. For extra comfort, the script can also create the zip file for deployment
  4. Once the installation finishes, the script will shutdown the VM to avoid unnecessary consumption of system resources
  5. Deploy!

如果链接库不在目标计算机上的同一位置,则可能需要进行一些调整,但是在我看来,这通常是最好和最快的解决方案.

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.

这篇关于使用node-gyp与本机绑定交叉编译节点模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆