【问题标题】:Canvas for Node.js working locally but not on Heroku server用于 Node.js 的画布在本地工作,但不在 Heroku 服务器上
【发布时间】:2016-05-23 20:24:38
【问题描述】:

我正在为 Node.js 使用 canvas package

它在我的计算机上运行良好,但是当我将它上传到我的 Heroku 服务器时它就无法运行。 “工作正常”是指使用 npm install canvas 正确安装的 canvas 包,并且 Node.js 应用程序按预期工作。

但是,当我尝试将其上传到 Heroku 并尝试构建 canvas 包时,我收到错误:

$ git push heroku master
Counting objects: 4304, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4028/4028), done.
Writing objects: 100% (4304/4304), 3.57 MiB | 606.00 KiB/s, done.
Total 4304 (delta 737), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Using set buildpack heroku/nodejs
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error

remote:        NPM_CONFIG_PRODUCTION=true
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  5.6.0
remote:        engines.npm (package.json):   3.7.2
remote:
remote:        Downloading and installing node 5.6.0...
remote:        Downloading and installing npm 3.7.2 (replacing version 3.6.0)...
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (new runtime signature)
remote:
remote: -----> Building dependencies
remote:        Prebuild detected (node_modules already exists)
remote:        Rebuilding any native modules
remote:
remote:        > canvas@1.3.10 install /tmp/build_565c08c270a791191b278953392f5493/node_modules/canvas
remote:        > node-gyp rebuild
remote:
remote:        make: Entering directory `/tmp/build_565c08c270a791191b278953392f5493/node_modules/canvas/build'
remote:        SOLINK_MODULE(target) Release/obj.target/canvas-postbuild.node
remote:        COPY Release/canvas-postbuild.node
remote:        CXX(target) Release/obj.target/canvas/src/Canvas.o
remote:        CXX(target) Release/obj.target/canvas/src/CanvasGradient.o
remote:        CXX(target) Release/obj.target/canvas/src/CanvasPattern.o
remote:        In file included from ../src/CanvasPattern.cc:9:0:
remote:        ../src/Image.h:19:21: fatal error: gif_lib.h: No such file or directory
remote:        #include <gif_lib.h>
remote:        ^
remote:        compilation terminated.

remote:        make: *** [Release/obj.target/canvas/src/CanvasPattern.o] Error 1
remote:        make: Leaving directory `/tmp/build_565c08c270a791191b278953392f5493/node_modules/canvas/build'
remote:        gyp ERR! build error
remote:        gyp ERR! stack Error: `make` failed with exit code: 2
remote:        gyp ERR! stack     at ChildProcess.onExit (/tmp/build_565c08c270a791191b278953392f5493/.heroku/node/lib/node_modules/npm/node_module
s/node-gyp/lib/build.js:276:23)
remote:        gyp ERR! stack     at emitTwo (events.js:100:13)
remote:        gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
remote:        gyp ERR! System Linux 3.13.0-71-generic
remote:        gyp ERR! command "/tmp/build_565c08c270a791191b278953392f5493/.heroku/node/bin/node" "/tmp/build_565c08c270a791191b278953392f5493/.h
eroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
remote:        gyp ERR! cwd /tmp/build_565c08c270a791191b278953392f5493/node_modules/canvas
remote:        gyp ERR! node -v v5.6.0
remote:        gyp ERR! node-gyp -v v3.2.1
remote:        gyp ERR! not ok
remote:
remote:        npm ERR! Linux 3.13.0-71-generic
remote:        npm ERR! argv "/tmp/build_565c08c270a791191b278953392f5493/.heroku/node/bin/node" "/tmp/build_565c08c270a791191b278953392f5493/.hero
ku/node/bin/npm" "rebuild"
remote:        npm ERR! node v5.6.0
remote:        npm ERR! npm  v3.7.2
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! canvas@1.3.10 install: `node-gyp rebuild`
remote:        npm ERR! Exit status 1
remote:        npm ERR!
remote:        npm ERR! Failed at the canvas@1.3.10 install script 'node-gyp rebuild'.
remote:        npm ERR! Make sure you have the latest version of node.js and npm installed.
remote:        npm ERR! If you do, this is most likely a problem with the canvas package,
remote:        npm ERR! not with npm itself.
remote:        npm ERR! Tell the author that this fails on your system:
remote:        npm ERR!     node-gyp rebuild

remote:        npm ERR! You can get information on how to open an issue for this project with:
remote:        npm ERR!     npm bugs canvas
remote:        npm ERR! Or if that isn't available, you can get their info via:
remote:        npm ERR!     npm owner ls canvas
remote:        npm ERR! There is likely additional logging output above.
remote:
remote:        npm ERR! Please include the following file with any support request:
remote:        npm ERR!     /tmp/build_565c08c270a791191b278953392f5493/npm-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:        Some possible problems:
remote:
remote:        - node_modules checked into source control
remote:        https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git

remote:
remote:        Love,
remote:        Heroku
remote:
remote:
remote:  !     Push rejected, failed to compile Node.js app
remote:
remote: Verifying deploy...
remote:
remote: !       Push rejected to colladraw.
remote:
To https://git.heroku.com/colladraw.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/colladraw.git'

错误具体在以下几行:

In file included from ../src/CanvasPattern.cc:9:0:
remote:        ../src/Image.h:19:21: fatal error: gif_lib.h: No such file or directory
remote:        #include <gif_lib.h>

remote:        ^
remote:        compilation terminated.

但是,我的系统上不存在这些问题。我摆弄了有关此问题的其他问题的解决方案,例如this questionthis question。问题是这两个都是本地机器,它们没有被推送到服务器,因此我无法在 Heroku 上解决问题。

可能的解决方案 1

看起来 Heroku 正在尝试根据以下几行自行重新构建所有包:

remote: -----> Building dependencies
remote:        Prebuild detected (node_modules already exists)
remote:        Rebuilding any native modules

我猜如果它不重新构建node_modules 并且只使用我计算机中的那个(那是工作),那么它也可以在服务器上工作。有没有办法阻止它自动重建?

可能的解决方案 2

Heroku 允许您运行one-off dynos,例如heroku run bash。这将打开一个连接到服务器的 bash 客户端。

我在想也许我可以直接在 Heroku 服务器上执行有关此问题的其他问题的解决方案。但是,它们非常严格,不允许sudo 访问,也不允许apt-get install。有什么办法可以规避吗?

随时提供其他想法。感谢您提供任何解决方案。

【问题讨论】:

标签: node.js canvas heroku


【解决方案1】:

node-canvas 依赖于Cairo,这是一个用 C 编写的图形库。Cairo 必须安装在您尝试部署到的任何服务器上。

如果您想部署到 Heroku,您可能必须使用自定义构建包。这里有如何做到这一点的示例文档:https://github.com/Automattic/node-canvas/wiki/Installation-on-Heroku

【讨论】:

  • 正是我需要的。我没看到这篇文章。谢谢!
  • 建议:不要使用该 Node-Canvas wiki 页面中的 multipack 存储库。您可以改用官方 Heroku 合装包:https://github.com/heroku/heroku-buildpack-multi.git。请参阅此处的说明:elements.heroku.com/buildpacks/heroku/…
  • 添加 cairo buildpack 后我得到了这个gzip: stdin: not in gzip format
猜你喜欢
  • 2018-03-04
  • 2021-04-28
  • 2016-11-05
  • 2014-11-16
  • 2018-12-05
  • 1970-01-01
  • 2017-08-01
  • 2016-10-18
  • 1970-01-01
相关资源
最近更新 更多