2016-03-24 13 views
6

Ich arbeite an einem kleinen Projekt Nodejs (Nodejs V4.3), die Knoten-Serialport https://github.com/voodootikigod/node-serialport verwendet. Ich wickelte es in ein Docker-Bild. Zuerst habe ich Debian erfolgreich als Basis-Image verwendet, aber es hatte eine Gesamtgröße von ca. 600MB. Dann wechselte ich auf alpine linux https://hub.docker.com/_/alpine/ und erreichte 100MB Bildgröße. Das Projekt nodejs hat jedoch nicht mehr mit alpine als Basis-Image gearbeitet. Hier sind einige Protokolle:Knoten-Serialport auf Alpine Linux Fehler

Installieren Knoten-Serialport Protokoll:

> [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]) 

Wenn ich versuche, einen seriellen Port zu öffnen, bekomme ich einen Fehler:

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) 

Wie gesagt, mit Debian als Basis Bild es hat funktioniert. Ich denke, es könnte mit der Tatsache zusammenhängen, dass alpine Linux etwas fehlt, von dem Knoten-Serialport abhängt. Ich habe ein Problem auf https://github.com/voodootikigod/node-serialport/issues/682 erstellt, aber ich bin mir nicht sicher, ob dies ein Problem mit Node-Serialport oder Alpine Linux ist. Ich habe gelesen, dass Knoten-Pre-gyp auf alpine/busybox fehlerhaft ist.

+0

haben Sie versucht, ubuntu ein Paket wie 'build-essentials' bei der Installation? – ArsalanDotMe

+0

@ArsalanDotMe ja, make und g ++ –

Antwort

6

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

Alpine ist eine (sehr) kleine Distro, aber es nutzt die MUSL Standardbibliothek statt glibc (das die meisten anderen Linux-Distributionen verwenden), so dass es Kompilation erfordert.

# 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 

Ich habe es getestet. Es löst das Problem.

+3

Ja, es ist auch in der README - https://github.com/voodootikigod/node-serialport#alpine-linux –

0

für mich Dies funktionierte in einem Docker Behälter Alpine Linux:

npm install serialport --unsafe-perm --build-from-source=serialport