如何在 64 位上为 32 位系统准备 node.js 个模块?

How to prepare node.js modules on 64bit for 32bit system?

我正在 64 位 Ubuntu 机器上开发一个 node.js 应用程序,我打算在 Raspberry Pi 运行ning Rasbpian 上 运行。 Pi 平时不联网,所以我手动将项目文件夹复制到它的 SD 卡中。我不能 运行 那里的应用程序,因为所需的模块之一 epoll,显然只适用于 64 位:

Error: /home/pi/bla/node_modules/epoll/build/Release/epoll.node: wrong ELF class: ELFCLASS64

at Object.Module._extensions..node (module.js:602:18)

at Module.load (module.js:507:32) at tryModuleLoad (module.js:470:12)

at Function.Module._load (module.js:462:3)

at Module.require (module.js:517:17)

at require (internal/module.js:11:18)

at bindings (/home/pi/bla/node_modules/bindings/bindings.js:76:44)

at Object. (/home/pi/bla/node_modules/epoll/epoll.js:1:99)

at Module._compile (module.js:573:30)

at Object.Module._extensions..js (module.js:584:10)

这可以通过 运行 宁 npm uninstall epoll 然后 npm install epoll 来解决,但只有当 Pi 连接到互联网时。当然我可以不复制这个特定的模块,但是有没有办法避免这个错误呢?

如果您在安装时没有互联网连接,那么唯一的方法是事先准备好 32 位和 64 位node_modules。首次启动时,只需检查您的 CPU 并将 node_modules 符号链接到 node_modules_64node_modules_32.

问题与复制无关,这是因为您试图 运行 在 32 位版本下使用 64 位 Node 版本编译的包。

在您的 Ubuntu 系统上使用相同位数的 Node 编译您的包(您可以在 64 位 OS 上安装 32 位 Node)然后 然后 复制过来。