Heroku部署失败(npm java)

我试图通过Heroku部署我的应用程序,这是在本地主机上完美工作。 尽pipe我在本地主机上安装Java模块时遇到了一些麻烦,但我终于做到了,感谢这篇文章: https : //github.com/nodejs/node/issues/10289 。

现在,我显然在Heroku上部署应用程序时出现同样的错误,但现在我无法修复它。 我甚至设置了Java Buildpack,以防万一,但它没有帮助。

我希望有人能帮助我!

这是我的package.json:

{ "name": "tachology", "version": "0.0.0", "main": "server/index.js", "dependencies": { "angular": "~1.6.0", "angular-animate": "~1.6.0", "angular-aria": "~1.6.0", "angular-cookies": "~1.6.0", "angular-resource": "~1.6.0", "angular-sanitize": "~1.6.0", "angular-ui-router": "^0.4.2", "angular-validation-match": "^1.9.0", "babel-polyfill": "^6.7.2", "babel-runtime": "^6.6.1", "bluebird": "^3.3.3", "body-parser": "^1.13.3", "cal-heatmap": "^3.6.2", "composable-middleware": "^0.3.0", "connect-mongo": "^1.2.1", "cookie-parser": "^1.3.5", "core-js": "^2.2.1", "errorhandler": "^1.4.2", "express": "^4.13.3", "express-jwt": "^5.0.0", "express-session": "^1.11.3", "fast-json-patch": "^1.0.0", "font-awesome": ">=4.1.0", "gridfs": "^1.0.0", "java": "^0.8.0", "jquery": "^3.2.1", "jsonformatter": "^0.6.0", "jsonwebtoken": "^7.0.0", "lodash": "^4.6.1", "lusca": "^1.3.0", "method-override": "^2.3.5", "mongoose": "^4.1.2", "morgan": "~1.7.0", "multer": "^1.3.0", "multer-gridfs-storage": "^1.2.2", "ng-google-charts": "^0.1.3", "passport": "~0.3.0", "passport-local": "^1.0.0", "pug": "2.0.0-beta4", "serve-favicon": "^2.3.0", "shrink-ray": "^0.1.3", "sprint-js": "~0.1.0", "uikit": "^3.0.0-beta.24" }, "devDependencies": { "angular-mocks": "~1.6.0", "autoprefixer": "^6.0.0", "babel-core": "^6.6.5", "babel-eslint": "^6.0.4", "babel-register": "^6.6.5", "browser-sync": "^2.8.0", "bs-fullscreen-message": "^1.0.0", "babel-plugin-transform-class-properties": "^6.6.0", "babel-plugin-transform-runtime": "^6.6.0", "babel-preset-es2015": "^6.6.0", "eslint": "^2.12.0", "del": "^2.0.2", "gulp": "^3.9.1", "gulp-babel": "^6.1.2", "gulp-env": "^0.4.0", "gulp-eslint": "^2.0.0", "gulp-imagemin": "^3.0.1", "gulp-inject": "^4.0.0", "gulp-istanbul": "^1.1.1", "gulp-istanbul-enforcer": "^1.0.3", "gulp-load-plugins": "^1.0.0-rc.1", "gulp-mocha": "^2.1.3", "gulp-node-inspector": "^0.1.0", "gulp-plumber": "^1.0.1", "gulp-protractor": "^3.0.0", "gulp-rev": "^7.0.0", "gulp-rev-replace": "^0.4.2", "gulp-sort": "^2.0.0", "gulp-sourcemaps": "^1.5.2", "gulp-util": "^3.0.5", "gulp-watch": "^4.3.5", "gulp-stylint": "^3.0.0", "grunt": "^1.0.1", "grunt-build-control": "^0.7.0", "isparta": "^4.0.0", "nodemon": "^1.3.7", "run-sequence": "^1.1.0", "lazypipe": "^1.0.1", "webpack": "^1.12.14", "webpack-dev-middleware": "^1.5.1", "webpack-stream": "^3.2.0", "extract-text-webpack-plugin": "^1.0.1", "html-webpack-plugin": "^2.16.0", "html-webpack-harddisk-plugin": "~0.0.2", "pug-html-loader": "^1.0.8", "awesome-typescript-loader": "0.17.0", "ng-annotate-loader": "~0.1.0", "babel-loader": "^6.2.4", "css-loader": "^0.24.0", "file-loader": "^0.9.0", "imports-loader": "^0.6.5", "isparta-instrumenter-loader": "^1.0.0", "isparta-loader": "^2.0.0", "istanbul-instrumenter-loader": "^0.2.0", "null-loader": "^0.1.1", "postcss-loader": "^0.11.1", "raw-loader": "^0.5.1", "style-loader": "^0.13.0", "node-sass": "^3.8.0", "sass-loader": "^4.0.1", "karma-webpack": "^1.7.0", "through2": "^2.0.1", "open": "~0.0.4", "istanbul": "1.1.0-alpha.1", "chai": "^3.2.0", "sinon": "^1.16.1", "chai-as-promised": "^5.1.0", "chai-things": "^0.2.0", "karma": "~0.13.3", "karma-firefox-launcher": "^1.0.0", "karma-script-launcher": "^1.0.0", "karma-coverage": "^1.0.0", "karma-chrome-launcher": "^2.0.0", "karma-phantomjs-launcher": "~1.0.0", "karma-spec-reporter": "~0.0.20", "karma-sourcemap-loader": "~0.3.7", "sinon-chai": "^2.8.0", "mocha": "^3.0.2", "jasmine-core": "^2.3.4", "karma-jasmine": "^1.0.2", "jasmine-spec-reporter": "^2.4.0", "phantomjs-prebuilt": "^2.1.4", "proxyquire": "^1.0.1", "strip-ansi": "^3.0.1", "supertest": "^1.1.0" }, "engines": { "node": "6.2.2", "npm": "3.9.5" }, "scripts": { "test": "gulp test", "update-webdriver": "node node_modules/protractor/bin/webdriver-manager update", "start": "node server" }, "private": true } 

这是部署时的日志:

 Warning: remote: Compressing source files... done. remote: Building source: remote: remote: -----> Node.js app detected remote: remote: -----> Creating runtime environment remote: remote: NPM_CONFIG_LOGLEVEL=error remote: NPM_CONFIG_PRODUCTION=true remote: NODE_VERBOSE=false remote: NODE_ENV=production remote: NODE_MODULES_CACHE=true remote: remote: -----> Installing binaries remote: engines.node (package.json): 6.2.2 remote: engines.npm (package.json): 3.9.5 remote: remote: Resolving node version 6.2.2... remote: Downloading and installing node 6.2.2... remote: npm 3.9.5 already installed with node remote: remote: -----> Restoring cache remote: Skipping cache restore (new-signature) remote: remote: -----> Building dependencies remote: Installing node modules (package.json) remote: remote: > iltorb@1.3.6 install /tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/iltorb remote: > node-pre-gyp install --fallback-to-build remote: remote: [iltorb] Success: "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/iltorb/build/bindings/iltorb.node" is installed via remote remote: remote: > node-zopfli@1.4.0 install /tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/node-zopfli remote: > node-pre-gyp install --fallback-to-build remote: remote: node-pre-gyp ERR! Tried to download(403): https://node-zopfli.s3.amazonaws.com/Release/zopfli-v1.4.0-node-v48-linux-x64.tar.gz remote: node-pre-gyp ERR! Pre-built binaries not found for node-zopfli@1.4.0 and node@6.2.2 (node-v48 ABI) (falling back to source compile with node-gyp) remote: make: Entering directory '/tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/node-zopfli/build' remote: CXX(target) Release/obj.target/zopfli/src/zopfli-binding.o remote: CXX(target) Release/obj.target/zopfli/src/png/zopflipng.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/blocksplitter.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/cache.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/deflate.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/gzip_container.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/hash.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/katajainen.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/lz77.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/squeeze.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/tree.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/util.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/zlib_container.o remote: CC(target) Release/obj.target/zopfli/zopfli/src/zopfli/zopfli_lib.o remote: CXX(target) Release/obj.target/zopfli/zopfli/src/zopflipng/zopflipng_lib.o remote: CXX(target) Release/obj.target/zopfli/zopfli/src/zopflipng/lodepng/lodepng.o remote: CXX(target) Release/obj.target/zopfli/zopfli/src/zopflipng/lodepng/lodepng_util.o remote: SOLINK_MODULE(target) Release/obj.target/zopfli.node remote: COPY Release/zopfli.node remote: COPY /tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/node-zopfli/lib/binding/node-v48-linux-x64/zopfli.node remote: TOUCH Release/obj.target/action_after_build.stamp remote: make: Leaving directory '/tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/node-zopfli/build' remote: remote: > java@0.8.0 install /tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/java remote: > node-gyp rebuild remote: remote: [node-java] Error: not found: javac remote: gyp: Call to 'node findJavaHome.js' returned exit status 1 while in binding.gyp. while trying to load binding.gyp remote: gyp ERR! configure error remote: gyp ERR! stack Error: `gyp` failed with exit code: 1 remote: gyp ERR! stack at ChildProcess.onCpExit (/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:305:16) remote: gyp ERR! stack at emitTwo (events.js:106:13) remote: gyp ERR! stack at ChildProcess.emit (events.js:191:7) remote: gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12) remote: gyp ERR! System Linux 3.13.0-128-generic remote: gyp ERR! command "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.heroku/node/bin/node" "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild" remote: gyp ERR! cwd /tmp/build_2beaa787f71f40bc41e528a14b9c399c/node_modules/java remote: gyp ERR! node -v v6.2.2 remote: gyp ERR! node-gyp -v v3.3.1 remote: gyp ERR! not ok remote: tachology@0.0.0 /tmp/build_2beaa787f71f40bc41e528a14b9c399c remote: ├── angular@1.6.6 remote: ... remote: ├── sprint-js@0.1.0 remote: └── uikit@3.0.0-beta.30 remote: remote: npm ERR! Linux 3.13.0-128-generic remote: npm ERR! argv "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.heroku/node/bin/node" "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.heroku/node/bin/npm" "install" "--unsafe-perm" "--userconfig" "/tmp/build_2beaa787f71f40bc41e528a14b9c399c/.npmrc" remote: npm ERR! node v6.2.2 remote: npm ERR! npm v3.9.5 remote: npm ERR! code ELIFECYCLE remote: remote: npm ERR! java@0.8.0 install: `node-gyp rebuild` remote: npm ERR! Exit status 1 remote: npm ERR! remote: npm ERR! Failed at the java@0.8.0 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 java 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 java remote: npm ERR! Or if that isn't available, you can get their info via: remote: npm ERR! npm owner ls java 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_2beaa787f71f40bc41e528a14b9c399c/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: 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 remote: Verifying deploy.... remote: remote: ! Push rejected to tachology. remote: To https://git.heroku.com/tachology.git ! [remote rejected] master -> master (pre-receive hook declined) error: failed to push some refs to 'https://git.heroku.com/tachology.git' Use --force to continue. Aborted due to warnings. 

看来你的node-gyp需要java被正确地构build。 Heroku的架构是只为您提供您指定/需要的东西。 现在我不认为Heroku明白它需要一个JVM来运行你的应用程序。 所以你应该提供一个buildpack。 一个简单的构build包是一套告诉Heroku设置,安装和构build的规则。 JVM有一个名为heroku/jvm的buildpack。 所以,你需要做的就是通过仪表板或者你的CLI通过heroku buildpacks:add heroku/jvm它添加到你的应用程序中heroku buildpacks:add heroku/jvm

还有一件事要做。 由于您的应用程序本身需要构build时需要javac,所以我们应该调用java / jvm的构build顺序。 所以在这种情况下,你应该做一个heroku buildpacks:add --index 1 heroku/jvm 。 这将JVM构build包放置在位置1,并按顺序推送每个其他构build包。

现在,当应用程序开始构build时,它首先设置JVM(从而为您的实例启用javac),然后运行NodeJS构build。 这个版本现在将从当前实例中获取javac并相应地生成。

参考: 在Heroku多元BuildPack