我無法將我的反應應用程式部署到 Heroku。它回傳此錯誤:
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/directto-web.git'
我不知道我做錯了什么。我之前已經將其他反應應用程式部署到 Heroku,但這從未發生過。我正在使用這個 buildpack。
從 Heroku 構建日志:
-----> Building on the Heroku-20 stack
-----> Using buildpack: mars/create-react-app
-----> React.js (create-react-app) multi app detected
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-multi.git
=====> Detected Framework: Multipack
=====> Downloading Buildpack: https://github.com/heroku/heroku-buildpack-nodejs.git
=====> Detected Framework: Node.js
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NODE_VERBOSE=false
NODE_ENV=production
NODE_MODULES_CACHE=true
-----> Installing binaries
engines.node (package.json): unspecified
engines.npm (package.json): unspecified (use default)
Resolving node version 16.x...
Downloading and installing node 16.14.2...
Using default npm version: 8.5.0
-----> Installing dependencies
Installing node modules (package.json)
added 1255 packages, and audited 1256 packages in 41s
174 packages are looking for funding
run `npm fund` for details
12 vulnerabilities (5 moderate, 7 high)
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
-----> Build
Running build
> directto_web@0.1.0 build
> react-scripts build
Creating an optimized production build...
Failed to compile.
Module not found: Error: Can't resolve '../../Assets/directto-logomarca.png' in '/tmp/build_b41f4669/src/Components/Searchbar'
-----> Build failed
We're sorry this build is failing! You can troubleshoot common issues here:
https://devcenter.heroku.com/articles/troubleshooting-node-deploys
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
Love,
Heroku
! Push rejected, failed to compile React.js (create-react-app) multi app.
! Push failed
我在構建日志上看到了這個錯誤:
Module not found: Error: Can't resolve '../../Assets/directto-logomarca.png' in '/tmp/build_b41f4669/src/Components/Searchbar'
我不知道為什么它無法決議檔案,因為它正好位于我指定的位置。有人能幫我嗎?
提前致謝。
編輯:我的 package.json。
{
"name": "directto_web",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.0.1",
"@testing-library/user-event": "^13.5.0",
"bootstrap": "^5.1.3",
"react": "^18.0.0",
"react-bootstrap": "^2.2.3",
"react-dom": "^18.0.0",
"react-icons": "^4.3.1",
"react-router": "^6.3.0",
"react-router-dom": "^6.3.0",
"react-scripts": "5.0.1",
"react-world-flags": "^1.4.0",
"styled-components": "^5.3.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
uj5u.com熱心網友回復:
您對資產目錄的參考很可能是錯誤的。當您通過參考當前檔案的相對檔案來匯入源代碼時,您應該像在公共目錄中一樣參考資產。
假設你有一個像這樣的結構
/public/
/assets/
/some.png
index.html
您應該從源代碼中參考您的資產檔案夾,例如
'assets/some.png'
好像 public 是你的根。基于通用 CRA 結構的假設。
如果這個假設是錯誤的,請分享您的檔案夾結構。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/460367.html
