节点串行端口在 alpine linux 上失败

2023-11-27

我正在开发一个使用node-serialport的小型nodejs(nodejs v4.3)项目https://github.com/voodootikigod/node-serialport。我把它包装在一个 docker 镜像中。首先,我成功使用 debian 作为基础镜像,但它的总大小约为 600MB。然后我切换到alpine linuxhttps://hub.docker.com/_/alpine/并实现了100MB的图像大小。然而,nodejs 项目停止使用 alpine 作为基础镜像。以下是一些日志:

安装节点串口日志:

> [email protected] install /app/node_modules/serialport
> node-pre-gyp install --fallback-to-build

[serialport] Success: "/app/node_modules/serialport/build/Release/node-v46-linux-x64/serialport.node" is installed via remote
[email protected] node_modules/serialport
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
└── [email protected] ([email protected], [email protected])

当我尝试打开串行端口时,出现错误:

npm ERR! Linux 3.19.0-30-generic
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "start"
npm ERR! node v4.3.0
npm ERR! npm  v2.14.12
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script 'node ./bin/www'.
npm ERR! This is most likely a problem with the app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node ./bin/www
npm ERR! You can get their info via:
npm ERR!     npm owner ls app
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /app/app/npm-debug.log
module.js:435
  return process.dlopen(module, path._makeLong(filename));
                 ^

Error: Error relocating /app/app/node_modules/serialport/build/Release/node-v46-linux-x64/serialport.node: __strcpy_chk: symbol not found
    at Error (native)
    at Object.Module._extensions..node (module.js:435:18)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/app/app/node_modules/serialport/serialport.js:14:25)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)

正如我所说,以 Debian 作为基础镜像,它可以工作。我认为这可能与 alpine linux 缺少 node-serialport 依赖的东西有关。我创建了一个问题https://github.com/voodootikigod/node-serialport/issues/682但我不确定这是否是节点串行端口或 alpine linux 的问题。我读到过有关 node-pre-gyp 在 alpine/busybox 上有问题的信息。


https://github.com/voodootikigod/node-serialport/pull/710

Alpine 是一个(非常)小的发行版,但它使用 musl 标准库而不是 glibc(大多数其他 Linux 发行版使用),因此它需要编译。

# If you don't have node/npm already, add that first
sudo apk add --no-cache nodejs

# Add the necessary build and runtime dependencies
sudo apk add --no-cache make gcc g++ python linux-headers udev

# Then we can install serialport, forcing it to compile
npm install serialport --build-from-source=serialport

我测试过。它解决了问题。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

节点串行端口在 alpine linux 上失败 的相关文章

随机推荐