Heroku build failing on dependency install

雨燕双飞 提交于 2021-02-10 19:51:52

问题


Node Canvas isn't installing on Heroku build, even though it works just fine on my own PC. I'm on nodejs version 12.16.3. I can't find a solution for this anywhere.

Canvas is a must, and I've never seen this error before until Heroku. Is this a problem with Heroku or a problem with my package/package-lock files?

My Discord is Tom Becker#0590 in case you need it.

Here's my build log:

-----> Node.js app detected
       
-----> Creating runtime environment
       
       NPM_CONFIG_LOGLEVEL=error
       NODE_ENV=production
       NODE_MODULES_CACHE=true
       NODE_VERBOSE=false
       
-----> Installing binaries
       engines.node (package.json):  12.x
       engines.npm (package.json):   unspecified (use default)
       
       Resolving node version 12.x...
       Downloading and installing node 12.18.1...
       Using default npm version: 6.14.5
       
-----> Installing dependencies
       Installing node modules (package.json + package-lock)
       
       > deasync@0.1.19 install /tmp/build_282e7f55032649968878bcdef8821199/node_modules/deasync
       > node ./build.js
       
       `linux-x64-node-12` exists; testing
       Binary is fine; exiting
       
       > canvas@2.6.1 install /tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas
       > node-pre-gyp install --fallback-to-build
       
       Package pangocairo was not found in the pkg-config search path.
       Perhaps you should add the directory containing `pangocairo.pc'
       to the PKG_CONFIG_PATH environment variable
       No package 'pangocairo' found
       gyp: Call to 'pkg-config pangocairo --libs' returned exit status 1 while in binding.gyp. while trying to load binding.gyp
       gyp ERR! configure error 
       gyp ERR! stack Error: `gyp` failed with exit code: 1
       gyp ERR! stack     at ChildProcess.onCpExit (/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
       gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
       gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
       gyp ERR! System Linux 4.4.0-1073-aws
       gyp ERR! command "/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/bin/node" "/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release" "--napi_version=6" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
       gyp ERR! cwd /tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas
       gyp ERR! node -v v12.18.1
       gyp ERR! node-gyp -v v5.1.0
       gyp ERR! not ok 
       node-pre-gyp ERR! build error 
       node-pre-gyp ERR! stack Error: Failed to execute '/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/bin/node /tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
       node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/tmp/build_282e7f55032649968878bcdef8821199/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
       node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
       node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
       node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
       node-pre-gyp ERR! System Linux 4.4.0-1073-aws
       node-pre-gyp ERR! command "/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/bin/node" "/tmp/build_282e7f55032649968878bcdef8821199/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
       node-pre-gyp ERR! cwd /tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas
       node-pre-gyp ERR! node -v v12.18.1
       node-pre-gyp ERR! node-pre-gyp -v v0.11.0
       node-pre-gyp ERR! not ok 
       Failed to execute '/tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/bin/node /tmp/build_282e7f55032649968878bcdef8821199/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release/canvas.node --module_name=canvas --module_path=/tmp/build_282e7f55032649968878bcdef8821199/node_modules/canvas/build/Release --napi_version=6 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
       npm ERR! code ELIFECYCLE
       npm ERR! errno 1
       npm ERR! canvas@2.6.1 install: `node-pre-gyp install --fallback-to-build`
       npm ERR! Exit status 1
       npm ERR! 
       npm ERR! Failed at the canvas@2.6.1 install script.
       npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
       
       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.3BVoV/_logs/2020-06-26T16_20_37_894Z-debug.log

-----> Build failed
       
       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys
       
       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/
       
       Love,
       Heroku
       
 !     Push rejected, failed to compile Node.js app.
 !     Push failed

回答1:


Looks like there is some issue with prebuilt packages. It can work depending on Node.js version, latest version which is worked for me is 14.14.0 so try to setup it in your package.json

  • v12.0.x succeeds
  • v12.16.x fails
  • v12.x.x fails
  • v13.0.x succeeds
  • v13.3.0 succeeds
  • v13.x.x fails
  • v14.0.x fails
  • v14.1.x fails
  • v14.14.0 succeeds
  • v15.0.1 fails

More about this here https://github.com/Automattic/node-canvas/issues/1563#issuecomment-625149050

I had similar issue after my builds switched from Node v14.14.0 to v15.0.1 after recent release https://nodejs.org/en/blog/release/v15.0.1/




回答2:


in addition to using a compatible node.js version (I'm using 13.3.0), I did two other things:

  • installed node-pre-gyp which seemed to pre-build everything correctly npm install node-pre-gyp@7.1.2
  • set heroku stack to 18: heroku stack:set heroku-18


来源:https://stackoverflow.com/questions/62599213/heroku-build-failing-on-dependency-install

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!