Search code examples
githubherokudeployment

git push to herok server fails, what should be the reason?


i am trying to push a react app to a heroku server. I have successfully pushed some react apps before but now its not working... here is the error message i get, when i run this code: git push heroku main

a lot of people are saying that the main branch master or main is protected and that i need to change it but i have no idea where i can do that and it doesnt really create a repository in my github either.

Total 47 (delta 0), reused 0 (delta 0), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
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 16.x...
remote:        Downloading and installing node 16.15.1...
remote:        Using default npm version: 8.11.0
remote:
remote: -----> Installing dependencies
remote:        Installing node modules
remote:        npm ERR! code EUSAGE
remote:        npm ERR!
remote:        npm ERR! `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.
remote:        npm ERR!
remote:        npm ERR! Invalid: lock file's [email protected] does not satisfy [email protected]
remote:        npm ERR! Missing: [email protected] from lock file
remote:        npm ERR! Invalid: lock file's [email protected] does not satisfy [email protected]
remote:        npm ERR!
remote:        npm ERR! Clean install a project
remote:        npm ERR!
remote:        npm ERR! Usage:
remote:        npm ERR! npm ci
remote:        npm ERR!
remote:        npm ERR! Options:
remote:        npm ERR! [--no-audit] [--foreground-scripts] [--ignore-scripts]
remote:        npm ERR! [--script-shell <script-shell>]
remote:        npm ERR!
remote:        npm ERR! aliases: clean-install, ic, install-clean, isntall-clean
remote:        npm ERR!
remote:        npm ERR! Run "npm help ci" for more info
remote:
remote:        npm ERR! A complete log of this run can be found in:
remote:        npm ERR!     /tmp/npmcache.qPgvy/_logs/2022-06-15T14_34_26_231Z-debug-0.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 test-this-deploy123.
remote:
To https://git.heroku.com/test-this-deploy123.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/test-this-deploy123.git'```

i looked everywhere but nothing has worked for me...
Can anybody please tell me what to do about this?!!?

Solution

  • I added this to my package.json and ran npm install and it pushed to heroku successfully

      "engines": {
        "node": "16.13.2",
        "npm": "8.1.2"
      }