When trying to push my app to Heroku I am getting the following errors (edited for brevity):
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): >=v12.22.5
remote: engines.npm (package.json): >=6.14.14
remote:
remote: Resolving node version >=v12.22.5...
remote: Could not parse Version Requirements '>=v12.22.5': the given version requirement is invalid
remote: Downloading and installing node 17.0.1...
remote: Bootstrapping npm >=6.14.14 (replacing 8.1.0)...
remote: npm >=6.14.14 installed
My package.json (name redacted):
{
"name": "########",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start -p $PORT"
},
"engines": {
"node": "16.13.0"
},
"dependencies": {
"@stripe/react-stripe-js": "^1.4.1",
"@stripe/stripe-js": "^1.15.0",
"@zeit/next-css": "^1.0.0",
"axios": "^0.21.4",
"base-64": "^1.0.0",
"bootstrap": "^4.6.0",
"cookie": "^0.4.1",
"date-and-time": "^1.0.0",
"js-cookie": "^2.2.1",
"next": "^11.1.2",
"react": "17.0.2",
"react-bootstrap": "^1.5.2",
"react-calendar": "^3.3.1",
"react-datepicker": "^4.2.1",
"react-dom": "17.0.2",
"react-hook-form": "^7.17.4",
"react-icons": "^4.2.0",
"react-image-gallery": "^1.0.9",
"stripe": "^8.154.0"
}
}
... and further down the error trail:
remote: Error: error:0308010C:digital envelope routines::unsupported
remote: at new Hash (node:internal/crypto/hash:67:19)
remote: at Object.createHash (node:crypto:130:10)
remote: at BulkUpdateDecorator.hashFactory (/tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:138971:18)
remote: at BulkUpdateDecorator.update (/tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:138872:50)
remote: at /tmp/build_f62151d1/node_modules/next/dist/compiled/webpack/bundle5.js:59321:9
remote: at processTicksAndRejections (node:internal/process/task_queues:83:21)
remote: at runNextTicks (node:internal/process/task_queues:65:3)
remote: at processImmediate (node:internal/timers:437:9) {
remote: opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
remote: library: 'digital envelope routines',
remote: reason: 'unsupported',
remote: code: 'ERR_OSSL_EVP_UNSUPPORTED'
remote: }
remote: Node.js v17.0.1
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: - Dangerous semver range (>) in engines.node
And, at the end of the error messages, I'm not sure if this is a separate error. I changed my master branch to main a while back and I'm not sure if this is also telling me that I may have done this incorrectly (seems fine on GitHub):
remote: Verifying deploy...
remote:
remote: ! Push rejected to #########.
remote:
To https://git.heroku.com/########.git
! [remote rejected] main -> main (pre-receive hook declined)
I have been 'around the houses' on Google trying various and many fixes with no answer that worked. It looks to me as if Heroku is reading the wrong information from my package.json? Many thanks for any replies.
CodePudding user response:
Got some help from Heroku support for this. My problem seemed to match a current use case that's currently out there online but I don't think this is the same. In case anyone else has the same issue I'll put my solutions here.
Heroku build was trying to automatically install version 17 of Node because it didn't understand the 'engines' version I had in my package.json at that time, and Heroku build is not compatible with version 17.x
The version of package.json 'stuck' in Heroku's build
"engines": {
"node": ">=v12.22.5"
},
But I changed that version multiple times during tesing and it seems Heroku didn't notice the changes to package.json. Heroku support told me to run a cache clearance and that worked. Once I ran the cache clearance Heroku build then picked up the correct version of Node from the 'engines' element. Here's how to clear the build cache
Install heroku-builds from the Heroku CLI
heroku plugins:install heroku-builds
Ensure the correct version of Node is on your local machine, but more importantly make sure the correct version is referenced in package.json. I decided on version 16.13.0
"engines": {
"node": "16.13.0"
},
Run the Heroku cache clearance
heroku builds:cache:purge -a example-app
Then redeploy your app. In my case the issue was fixed. Not sure if Heroku agree (and I'm not qualified to argue) but I feel the error in the end was because the cache needed to be cleared.
References:
Clear the build cache:
https://help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache
Supported Node versions:
https://devcenter.heroku.com/articles/nodejs-support#supported-runtimes