heroku推送被拒绝,无法编译Node.js应用

时间:2019-06-11 06:02:02

标签: git heroku discord.js heroku-api

当我尝试将Node.js应用程序部署到Heroku时,我不断收到node-pre-gypgyp错误:

$ git push -f heroku master
Enumerating objects: 48, done.
Counting objects: 100% (48/48), done.
Delta compression using up to 4 threads
Compressing objects: 100% (42/42), done.
Writing objects: 100% (48/48), 3.33 MiB | 232.00 KiB/s, done.
Total 48 (delta 3), reused 0 (delta 0)
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_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version (latest stable) via semver.io...
remote:        Downloading and installing node 12.4.0...
remote:        Using default npm version: 6.9.0
remote:
remote: -----> Restoring cache
remote:        Skipping cache restore (new runtime signature)
remote:
remote: -----> Building dependencies
remote:        Pruning any extraneous modules
remote:
remote:        > node@12.4.0 preinstall node_modules/node
remote:        > node installArchSpecificPackage
remote:
remote:        + node-linux-x64@12.4.0
remote:        added 1 package in 1.966s
remote:        found 0 vulnerabilities
remote:
remote:
remote:        > lzma-native@3.0.8 install node_modules/decompress-tarxz/node_modules/lzma-native
remote:        > node-pre-gyp install --fallback-to-build && node node_modules/rimraf/bin.js build
remote:
remote:        node-pre-gyp ERR! Tried to download(404): https://node-pre-gyp.addaleax.net/lzma-native/lzma_native-v3.0.8-node-v72-linux-x64.tar.gz
remote:        node-pre-gyp ERR! Pre-built binaries not found for lzma-native@3.0.8 and node@12.4.0 (node-v72 ABI, glibc) (falling back to source compile with node-gyp)
remote:        node-pre-gyp ERR! Tried to download(undefined): https://node-pre-gyp.addaleax.net/lzma-native/lzma_native-v3.0.8-node-v72-linux-x64.tar.gz
remote:        node-pre-gyp ERR! Pre-built binaries not found for lzma-native@3.0.8 and node@12.4.0 (node-v72 ABI, glibc) (falling back to source compile with node-gyp)
remote:        gyp: Call to 'sh liblzma-config.sh "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/build" "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/deps/xz-5.2.3.tar.bz2"' returned exit status 77 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_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
remote:        gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
remote:        gyp ERR! System Linux 4.4.0-1044-aws
remote:        gyp ERR! command "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/bin/node" "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64/lzma_native.node" "--module_name=lzma_native" "--module_path=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64"
remote:        gyp ERR! cwd /tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native
remote:        gyp ERR! node -v v12.4.0
remote:        gyp ERR! node-gyp -v v3.8.0
remote:        gyp ERR! not ok
remote:        node-pre-gyp ERR! build error
remote:        node-pre-gyp ERR! stack Error: Failed to execute '/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/bin/node /tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64/lzma_native.node --module_name=lzma_native --module_path=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64' (1)
remote:        node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
remote:        node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
remote:        node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1021:16)
remote:        node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5)
remote:        node-pre-gyp ERR! System Linux 4.4.0-1044-aws
remote:        node-pre-gyp ERR! command "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/bin/node" "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
remote:        node-pre-gyp ERR! cwd /tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native
remote:        node-pre-gyp ERR! node -v v12.4.0
remote:        node-pre-gyp ERR! node-pre-gyp -v v0.6.39
remote:        node-pre-gyp ERR! not ok
remote:        Failed to execute '/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/bin/node /tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64/lzma_native.node --module_name=lzma_native --module_path=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64' (1)
remote:        gyp: Call to 'sh liblzma-config.sh "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/build" "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/deps/xz-5.2.3.tar.bz2"' 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_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:345:16)
remote:        gyp ERR! stack     at ChildProcess.emit (events.js:200:13)
remote:        gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
remote:        gyp ERR! System Linux 4.4.0-1044-aws
remote:        gyp ERR! command "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/bin/node" "/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64/lzma_native.node" "--module_name=lzma_native" "--module_path=/tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native/binding-v3.0.8-node-v72-linux-x64"
remote:        gyp ERR! cwd /tmp/build_b7e92bed257ad47ee5287fa74d7875ac/node_modules/decompress-tarxz/node_modules/lzma-native
remote:        gyp ERR! node -v v12.4.0
remote:        gyp ERR! node-gyp -v v3.8.0
remote:        gyp ERR! not ok
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! errno 1
remote:        npm ERR! lzma-native@3.0.8 install: `node-pre-gyp install --fallback-to-build && node node_modules/rimraf/bin.js build`
remote:        npm ERR! Exit status 1
remote:        npm ERR!
remote:        npm ERR! Failed at the lzma-native@3.0.8 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!     /app/.npm/_logs/2019-06-11T04_42_23_817Z-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 version not specified in package.json
remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
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 multicommand-discordbot.
remote:
To https://git.heroku.com/multicommand-discordbot.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/multicommand-discordbot.git'

npm install之后,我又遇到另一个错误:

$ npm install

> ffmpeg-binaries@4.0.0 install D:\Workspace\DiscordBot\node_modules\ffmpeg-binaries
> node install

internal/modules/cjs/loader.js:626
    throw err;
    ^

Error: Cannot find module 'D:\Workspace\DiscordBot\node_modules\decompress-tarxz\node_modules\lzma-native\binding-v3.0.8-node-v72-win32-x64\lzma_native.node'
Require stack:
- D:\Workspace\DiscordBot\node_modules\decompress-tarxz\node_modules\lzma-native\index.js
- D:\Workspace\DiscordBot\node_modules\decompress-tarxz\index.js
- D:\Workspace\DiscordBot\node_modules\ffmpeg-binaries\install.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:623:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at D:\Workspace\DiscordBot\node_modules\decompress-tarxz\node_modules\lzma-native\index.js:13:14
    at Object.<anonymous> (D:\Workspace\DiscordBot\node_modules\decompress-tarxz\node_modules\lzma-native\index.js:597:3)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'D:\\Workspace\\DiscordBot\\node_modules\\decompress-tarxz\\node_modules\\lzma-native\\index.js',
    'D:\\Workspace\\DiscordBot\\node_modules\\decompress-tarxz\\index.js',
    'D:\\Workspace\\DiscordBot\\node_modules\\ffmpeg-binaries\\install.js'
  ]
}
npm WARN discordbot@0.1.0 No description
npm WARN discordbot@0.1.0 No repository field.
npm WARN discordbot@0.1.0 No license field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ffmpeg-binaries@4.0.0 install: `node install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ffmpeg-binaries@4.0.0 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!     C:\Users\Asus\AppData\Roaming\npm-cache\_logs\2019-06-11T05_01_23_916Z-debug.log

这是我的package.json

{
    "name": "discordbot",
    "version": "0.1.0",
    "Description": "A bot filled with different kind of things! suggest now",
    "main": "main.js",
    "dependencies": {
        "discord.js": "^11.5.0",
        "ffmpeg-binaries": "^4.0.0",
        "google-images": "^2.1.0",
        "image-search-google": "^1.3.0",
        "long": "^4.0.0",
        "lzma-native": "^4.0.3",
        "ms": "^2.1.1",
        "node": "^12.4.0",
        "node-google-image-search": "^1.0.3",
        "node-gyp": "^4.0.0",
        "nodemon": "^1.19.1",
        "npm": "^6.3.0",
        "opusscript": "0.0.6",
        "rebuild": "^0.1.2",
        "simple-youtube-api": "^5.1.1",
        "yt-search": "^0.4.1",
        "ytdl-core": "^0.29.2"
    },
    "devDependencies": {},
    "keywords": [],
    "author": "TommyWaltion",
    "lincense": "ISC"
}

如何将我的应用程序成功部署到Heroku?

1 个答案:

答案 0 :(得分:0)

您没有告诉Heroku使用哪个版本的Node.js和NPM,因此它默认为最新版本:

remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version (latest stable) via semver.io...
remote:        Downloading and installing node 12.4.0...
remote:        Using default npm version: 6.9.0

由于某种原因,Node.js版本不匹配通常与node-pre-gyp错误有关。尝试通过adding an engines section to your package.json告诉Heroku使用Node.js版本10,就像您在本地使用一样:

"engines": {
  "node": "10.x"
}