Come faccio a distribuire la mia app Node.js con una dipendenza opencv4nodejs in Heroku?

Sto cercando di distribuire la mia app Express Node.Js su Heroku, ma sto riscontrando problemi con OpenCV nella fase di costruzione. Sto usando opencv4nodejs .

Ho lo stesso problema con questo thread nell’app Heroku NodeJS che usa OpenCV , e dopo aver provato anche diversi tipi di builder OpenCV Heroku e seguendo le istruzioni di quella risposta, non riesco ancora a farlo funzionare.

Ecco il mio package.json :

 { "name": "open-cv-project", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "engines": { "node": "9.5.0", "npm": "4.6.1" }, "author": "", "license": "ISC", "dependencies": { "async": "^2.6.1", "aws-sdk": "^2.272.1", "cheerio": "^1.0.0-rc.2", "compromise": "^11.11.0", "express": "^4.16.3", "google-spreadsheet": "^2.0.5", "moment": "^2.22.2", "opencv4nodejs": "^4.6.1", "q": "^1.5.1", "request": "^2.87.0", "request-promise": "^4.2.2", "rss-feed-emitter": "^2.0.0", "sharp": "^0.20.5", "underscore": "^1.9.1", "underscore.string": "^3.3.4", "winston": "^2.3.0" } } 

Ecco i log da provare a git push su Heroku:

 My-Macbook:open-cv-project guy$ git push staging Counting objects: 37, done. Delta compression using up to 8 threads. Compressing objects: 100% (36/36), done. Writing objects: 100% (37/37), 47.67 MiB | 643.00 KiB/s, done. Total 37 (delta 20), reused 0 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> opencv app detected remote: -----> Fetching and caching OpenCV (a4c8444d7bae2a219b4ea9cb68919637) remote: -----> Vendoring OpenCV shared objects into slug remote: -----> Node.js app detected remote: remote: -----> Creating runtime environment remote: remote: NPM_CONFIG_LOGLEVEL=error remote: NODE_VERBOSE=false remote: NODE_ENV=production remote: NODE_MODULES_CACHE=true remote: remote: -----> Installing binaries remote: engines.node (package.json): 9.5.0 remote: engines.npm (package.json): 4.6.1 remote: remote: Resolving node version 9.5.0... remote: Downloading and installing node 9.5.0... remote: Bootstrapping npm 4.6.1 (replacing 5.6.0)... remote: npm 4.6.1 installed remote: remote: -----> Restoring cache remote: Skipping cache restore (new-signature) remote: remote: -----> Building dependencies remote: Installing node modules (package.json + package-lock) remote: remote: > [email protected] install /tmp/build_d2fff4256863b9d50ec7ab06c3b8e915/node_modules/opencv-build remote: > node ./install.js remote: remote: info install if you want to use an own OpenCV installation set OPENCV4NODEJS_DISABLE_AUTOBUILD remote: info install library dir does not exist: /tmp/build_d2fff4256863b9d50ec7ab06c3b8e915/node_modules/opencv-build/opencv/build/lib remote: info install running install script... remote: ERR! Error: Command failed: cmake --version remote: /bin/sh: 1: cmake: not found remote: remote: [email protected] /tmp/build_d2fff4256863b9d50ec7ab06c3b8e915 remote: ├─┬ [email protected] remote: │ └── [email protected] remote: ├─┬ [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ └─┬ [email protected] remote: │ ├── [email protected] deduped remote: │ └── [email protected] remote: ├─┬ [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ └─┬ [email protected] remote: │ │ └── [email protected] deduped remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ └─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] deduped remote: │ └─┬ [email protected] remote: │ └── @types/[email protected] remote: ├─┬ [email protected] remote: │ └── [email protected] remote: ├─┬ [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] remote: │ │ │ │ ├── [email protected] deduped remote: │ │ │ │ ├── [email protected] remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── http-e[email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ └── [email protected] remote: ├─┬ [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ └── [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] remote: │ │ │ │ ├─┬ [email protected] remote: │ │ │ │ │ └── [email protected] deduped remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ ├── [email protected] deduped remote: │ └── [email protected] deduped remote: ├── [email protected] remote: ├── [email protected] remote: ├─┬ [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ ├─┬ [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ └── [email protected] remote: │ │ └── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ └─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ └─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected]2.1.0 remote: │ ├── [email protected] deduped remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] deduped remote: │ └── [email protected] deduped remote: ├─┬ [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ └── [email protected] deduped remote: │ ├── [email protected] remote: │ └── [email protected] deduped remote: ├─┬ [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ └── [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ └─┬ [email protected] remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ └─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] deduped remote: │ └── [email protected] remote: ├─┬ [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] remote: │ │ └─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ └─┬ [email protected] remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] remote: │ │ │ │ ├─┬ [email protected] remote: │ │ │ │ │ └── [email protected] remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ └── [email protected] remote: │ │ │ └─┬ wide-ali[email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ └── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] deduped remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ └─┬ [email protected] remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] deduped remote: │ │ │ │ └── [email protected] deduped remote: │ │ │ ├─┬ [email protected] remote: │ │ │ │ ├── [email protected] remote: │ │ │ │ └── [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ ├── [email protected] remote: │ │ │ └── [email protected] remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] remote: │ ├── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] remote: │ │ └── [email protected] remote: │ ├─┬ [email protected] remote: │ │ ├── [email protected] remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ ├── [email protected] deduped remote: │ │ │ └── [email protected] deduped remote: │ │ ├─┬ [email protected] remote: │ │ │ └── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ ├── [email protected] deduped remote: │ │ └── [email protected] remote: │ └── [email protected] deduped remote: ├── [email protected] remote: ├─┬ [email protected] remote: │ ├── [email protected] remote: │ └── [email protected] remote: └─┬ [email protected] remote: ├── [email protected] remote: ├── [email protected] remote: ├── [email protected] remote: ├── [email protected] remote: ├── [email protected] deduped remote: └── [email protected] remote: remote: npm ERR! code ELIFECYCLE remote: npm ERR! errno 1 remote: npm ERR! [email protected] install: `node ./install.js` remote: npm ERR! Exit status 1 remote: npm ERR! remote: npm ERR! Failed at the [email protected] install script. remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. remote: remote: npm ERR! A complete log of this run can be found in: remote: npm ERR! /tmp/npmcache.s30Rg/_logs/2018-07-15T17_55_57_804Z-debug.log remote: remote: -----> Build failed remote: remote: We're sorry this build is failing! You can troubleshoot common issues here: remote: https://devcenter.heroku.com/articles/troubleshooting-node-deploys remote: remote: If you're stuck, please submit a ticket so we can help: remote: https://help.heroku.com/ remote: remote: Love, remote: Heroku remote: remote: ! Push rejected, failed to compile Node.js app. remote: remote: ! Push failed 

Ho anche eseguito heroku run bash per provare a installare manualmente via npm install opencv4nodejs sul server Heroku, e vedere questo errore:

     ~ $ npm install opencv4nodejs > [email protected] install /app/node_modules/opencv-build > node ./install.js info install OPENCV4NODEJS_DISABLE_AUTOBUILD is set info install skipping auto build... > [email protected] install /app/node_modules/opencv4nodejs > node-gyp rebuild make: Entering directory '/app/node_modules/opencv4nodejs/build' CXX(target) Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o make: g++: Command not found opencv4nodejs.target.mk:195: recipe for target 'Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o' failed make: *** [Release/obj.target/opencv4nodejs/cc/opencv4nodejs.o] Error 127 make: Leaving directory '/app/node_modules/opencv4nodejs/build' 

    Gradirei qualsiasi aiuto!

    Dopo molta persistenza, finalmente ho trovato la soluzione così rispondendo alla mia stessa domanda:

    Se il tuo stack è heroku-16 , questi sono i buildpack di Heroku che vuoi aggiungere (in questo particolare ordine!):

    Herku