0

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 type-fest@0.21.3 does not satisfy type-fest@0.13.1
remote:        npm ERR! Missing: type-fest@0.21.3 from lock file
remote:        npm ERR! Invalid: lock file's typescript@4.6.3 does not satisfy typescript@3.9.10
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?!!?
masafood
  • 325
  • 2
  • 11
  • The error tells you exactly what the problem is, and more importantly, what the _solution_ is: `\`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`. Run `npm install` locally, commit the updated lock file, and redeploy. – ChrisGPT was on strike Jun 15 '22 at 14:51
  • obvisouly i tried npm install to update the json files – masafood Jun 15 '22 at 14:52
  • Don't say "obviously" for things that aren't obvious. Nowhere in your question do you say that you did that. Did you _commit_ the updated lock file? Why are your lock file and `package.json` out of sync if you already did this? Please read [ask], then [edit] your question to add all relevant information. – ChrisGPT was on strike Jun 15 '22 at 14:55
  • sorry about that Chris, yes I did try npm install as it says but not sure on how to commit the updated lock file... . I didnt want to come across rude or anything. and it seemed like there are different problems with my deployment, i didnt really specify in the title as i was afrid i would pointing at the wrong cause. thank you for your reply though – masafood Jun 15 '22 at 18:45
  • i also found this to be my node verions: "engines": { "node": ">=6.0.0" } – masafood Jun 15 '22 at 18:51
  • I'm also hitting this same problem, and I'm also using node 16.15.1 with npm 8.11.0. I have deleted the node_modules folder and the package-lock.json numerous times, and re-run "npm install" to regenerate a new package-lock.json. I then immediately follow that with "npm ci", and I get the error you are reporting: ```npm ERR! Invalid: lock file's type-fest@0.21.3 does not satisfy type-fest@0.13.1 npm ERR! Missing: type-fest@0.21.3 from lock file```. This in my local node environment on Windows 10, Heroku. In my case it is also a React app. Did you recently upgrade node/npm? – tlfu Jun 15 '22 at 20:35
  • I meant to say, this is on Windows 10, NOT Heroku, in my case. – tlfu Jun 15 '22 at 20:46

3 Answers3

3

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"
  }
masafood
  • 325
  • 2
  • 11
1

Not sure my "answer" is pertinent to your original question, but in my case, I was getting this error during the "npm ci" operation (which is similar to the error in your original question):

53 verbose stack Error: 
53 verbose stack `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.
53 verbose stack
53 verbose stack Invalid: lock file's type-fest@0.21.3 does not satisfy type-fest@0.13.1
53 verbose stack Missing: type-fest@0.21.3 from lock file
53 verbose stack

I re-ran the "npm install" operation with "silly" loglevel and saw that multiple versions of type-fest were installed as dependencies:

6817 silly audit   'type-fest': [ '0.21.3', '0.8.1', '0.6.0', '0.3.1', '0.20.2' ],

However, version 0.13.1 was NOT installed. This version is listed as a peer dependency of the "React Refresh Webpack Plugin" (@pmmmwh/react-refresh-webpack-plugin). In my case, I solved this problem by explicitly adding

"type-fest": "^0.13.1"
as a dependency of my package. Maybe not the best way to solve it, but I've spent too much time trying to get this straightened out already.
tlfu
  • 171
  • 4
  • what worked for me was is the code i added below to my own question, i put speicifed the current node/npm version and it got deployed successfully to Heroku, but for your sitution, it looks very similar to mine and tried the same npm install and nothing got solved... it wasnt as straightforward as npm install. your package lock file has to have the specified engines, if you are still having the same problem, try the code below.... – masafood Jun 19 '22 at 11:15
1

None of the previous answers mention it, but adding a dependency of your dependency is NOT a correct way to solve those kinds of issues.

Update your local installation of NPM to a version greater than 8.6.0. Then run npm i and commit and push relevant package-lock.json.

There was a bug in npm's dependency resolvement algorithm which was not obvious at the time and because of it older versions of npm would not include type-fest^0.13.1 in package-lock.json.

In versions before 8.6.0 npm would blindly install whatever was mentioned in package-lock.json. Starting from 8.6.0 npm now checks the package-lock.json for all peer dependencies.

Because of this, many people using the latest npm version in their CI environments would get errors saying that package.json and package-lock.json are not in sync.

See this issue on npm for more details.

irdkwmnsb
  • 303
  • 2
  • 9
  • This is a better _looking_ answer than any of the previous (and I'm convinced it's helpful), but I'm still getting a similar error: `Invalid: lock file's type-fest@0.20.2 does not satisfy type-fest@0.13.1` – Drew Wills Jul 28 '22 at 10:17