我對Node.js使用canvas package。Canvas for Node.js在本地工作,但不在Heroku服務器上
它可以在我的電腦上正常工作,但是當我將它上傳到我的Heroku服務器時它不起作用。通過「正常工作」,我的意思是正確安裝的畫布包與npm install canvas
和Node.js應用程序按預期工作。
然而,當我試圖把它上傳到Heroku的,並嘗試構建帆布包,我得到的錯誤:
$ 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: > [email protected] 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! [email protected] install: `node-gyp rebuild`
remote: npm ERR! Exit status 1
remote: npm ERR!
remote: npm ERR! Failed at the [email protected] 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 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
。有什麼辦法可以繞過這個嗎?
隨意提供更多的想法。感謝任何解決方案。
http://stackoverflow.com/a/40310421/3310334 – theonlygusti