Error: failed to push some refs in heroku

Error: failed to push some refs in heroku

我正在学习有关如何在 Heroku 中进行部署的在线课程。我创建了一个 Git 存储库并上传并提交了所有文件。然后我输入了这些命令:

  1. heroku create
  2. heroku git:remote -a name_provided_by_heroku
  3. git push heroku main

在命令 3 之后,我在 cmd 中遇到了这个错误:

Enumerating objects: 4357, done.
Counting objects: 100% (4357/4357), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4125/4125), done.
Writing objects: 100% (4357/4357), 3.64 MiB | 297.00 KiB/s, done.
Total 4357 (delta 935), reused 3 (delta 0), pack-reused 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:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  unspecified
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 12.x...
remote:        Downloading and installing node 12.20.0...
remote:        Using default npm version: 6.14.8
remote:
remote: -----> Installing dependencies
remote:        Prebuild detected (node_modules already exists)
remote:        Rebuilding any native modules
remote:
remote:        > bcrypt@5.0.0 install /tmp/build_88514da7/node_modules/bcrypt
remote:        > node-pre-gyp install --fallback-to-build
remote:
remote:        sh: 1: node-pre-gyp: Permission denied
remote:        npm ERR! code ELIFECYCLE
remote:        npm ERR! errno 126
remote:        npm ERR! bcrypt@5.0.0 install: `node-pre-gyp install --fallback-to-build`
remote:        npm ERR! Exit status 126
remote:        npm ERR!
remote:        npm ERR! Failed at the bcrypt@5.0.0 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!     /tmp/npmcache.MO7JR/_logs/2020-12-15T17_16_14_007Z-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://devcenter.heroku.com/articles/node-best-practices#only-git-the-important-bits
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 safe-dawn-68695.
remote:
To https://git.heroku.com/safe-dawn-68695.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/safe-dawn-68695.git'

我是 Heroku 的新手,所以我无法理解错误的意思。也尝试使用 git push heroku HEAD:master 但遇到同样的错误。

我该如何解决?

参考这篇文章:node-pre-gyp: Permission denied in heroku push

Remove node_modules folder in your root folder rm -rf node_modules beacuse heroku will install all your dependencies, I hope this will work

因此删除您的节点模块文件夹并再次执行 1 2 3