嘗試將我的應用程式推送到 Heroku 時,出現以下錯誤(為簡潔起見進行了編輯):
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
我的 package.json (名稱已編輯):
{
"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"
}
}
...并進一步跟蹤錯誤:
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
而且,在錯誤訊息的末尾,我不確定這是否是一個單獨的錯誤。不久前我將主分支更改為 main ,我不確定這是否也告訴我我可能做錯了(在 GitHub 上看起來不錯):
remote: Verifying deploy...
remote:
remote: ! Push rejected to #########.
remote:
To https://git.heroku.com/########.git
! [remote rejected] main -> main (pre-receive hook declined)
我一直在 Google 的“房子周圍”嘗試各種修復方法,但沒有任何解決方法。在我看來,Heroku 從我的 package.json 中讀取了錯誤的資訊?非常感謝您的回復。
uj5u.com熱心網友回復:
從 Heroku 支持那里得到了一些幫助。我的問題似乎與當前在線的用例相匹配,但我認為這不一樣。如果其他人有同樣的問題,我會將我的解決方案放在這里。
Heroku build 試圖自動安裝 Node 17 版本,因為它當時不理解我在 package.json 中的“引擎”版本,并且 Heroku build 與版本 17.x 不兼容
在 Heroku 的構建中“卡住”的 package.json 版本
"engines": {
"node": ">=v12.22.5"
},
但是我在測驗期間多次更改了該版本,而且 Heroku 似乎沒有注意到 package.json 的更改。Heroku 支持人員告訴我運行快取清除并且有效。一旦我運行快取清除 Heroku 構建,然后從“引擎”元素中選擇正確版本的 Node。這是清除構建快取的方法
從 Heroku CLI 安裝 heroku-builds
heroku plugins:install heroku-builds
確保您的本地機器上有正確的 Node 版本,但更重要的是確保在 package.json 中參考了正確的版本。我決定使用 16.13.0 版本
"engines": {
"node": "16.13.0"
},
運行 Heroku 快取清除
heroku builds:cache:purge -a example-app
然后重新部署您的應用程式。就我而言,問題已解決。不確定 Heroku 是否同意(我沒有資格爭論)但我覺得最終的錯誤是因為需要清除快取。
參考:
清除構建快取:https :
//help.heroku.com/18PI5RSY/how-do-i-clear-the-build-cache
支持的節點版本:https :
//devcenter.heroku.com/articles/nodejs-support#supported-runtimes
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/351683.html
