heroku push 被拒绝,无法编译 Node.js 应用程序

Posted

技术标签:

【中文标题】heroku push 被拒绝,无法编译 Node.js 应用程序【英文标题】:heroku push rejected, failed to compile Node.js app 【发布时间】:2019-10-25 12:05:07 【问题描述】:

当我尝试将 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?

【问题讨论】:

(a) 您是否在本地使用 Node.js 版本 12?如果不是(即使你是),你可能应该set the version you want in your package.json。 (b) 你想在哪里运行npm install 我的node.js版本是v10.16.0不知道你说的本地是什么意思,我是在所有node模块的文件夹里面运行的,package.json是跨度> “本地”是指在您的开发机器上。您是否按照我之前的建议使用engines 键尝试将setting the Node.js version on Heroku 升级到10.16.0(或10.x)?目前 Heroku 正在使用 Node.js 12,这可能会导致问题。 【参考方案1】:

你没有告诉 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"

【讨论】:

这也可能是由于 npm 版本不匹配造成的,在这种情况下,将适当的 npm 版本添加到“engines”部分可以解决问题。

以上是关于heroku push 被拒绝,无法编译 Node.js 应用程序的主要内容,如果未能解决你的问题,请参考以下文章

node-pre-gyp:heroku push 中的权限被拒绝

node-pre-gyp:heroku push 中的权限被拒绝

Heroku 部署 - “推送被拒绝,无法编译 Node.js 应用程序”

Heroku 构建失败 - 推送被拒绝,无法编译 node.js 应用程序,无法缩小包,许多错误

git push heroku master错误权限被拒绝(公钥)[重复]

git push heroku master:Heroku push 被拒绝,没有检测到 Cedar 支持的应用程序