高山Linux上的node-serialport失败 [英] node-serialport failing on alpine linux

查看:261
本文介绍了高山Linux上的node-serialport失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个使用node-serialport https://github.com的小型nodejs(nodejs v4.3)项目。 / voodootikigod / node-serialport 。我将其包装在docker映像中。首先,我成功地使用了debian作为基本映像,但其总大小约为600MB。然后我切换到Alpine Linux https://hub.docker.com/_/alpine/ 并获得了100MB的图像尺寸。但是,nodejs项目停止使用alpine作为基础映像。以下是一些日志:

I am working on a small nodejs (nodejs v4.3) project that is using node-serialport https://github.com/voodootikigod/node-serialport. I wrapped it in a docker image. First I successfully used debian as a base image but it had a total size of about 600MB. Then I switched to alpine linux https://hub.docker.com/_/alpine/ and achieved 100MB of image size. However the nodejs project stopped working with alpine as base image. Here are some logs:

安装节点串行端口日志:

Install node-serialport log:

> serialport@2.0.6 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
serialport@2.0.6 node_modules/serialport
├── bindings@1.2.1
├── async@0.9.0
├── sf@0.1.7
├── debug@2.2.0 (ms@0.7.1)
├── nan@2.0.9
└── optimist@0.6.1 (wordwrap@0.0.3, minimist@0.0.10)

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

When I try to open a serial port I get an error:

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! app@1.2.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the app@1.2.0 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为基础映像可以正常工作。我认为这可能与以下事实有关:高山linux缺少node-serialport依赖的内容。我在 https://github.com/voodootikigod/node-serialport/issues/682 上创建了一个问题但是我不确定这是node-serialport还是alpine linux的问题。我读到关于节点预gyp在alpine / busybox上有错误的消息。

As I said, with debian as base image it worked. I think it could be related to the fact that alpine linux is missing something that node-serialport depends on. I created an issue on https://github.com/voodootikigod/node-serialport/issues/682 but I am not sure if this is a problem with node-serialport or with alpine linux. I read about node-pre-gyp being buggy on alpine/busybox.

推荐答案

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

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

Alpine is a (very) small distro, but it uses the musl standard library instead of glibc (that most other Linux distros use), so it requires compilation.

# 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

我测试了它。它可以解决问题。

I tested it. It solves the problem.

这篇关于高山Linux上的node-serialport失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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