我使用 create-react-app 構建了我的應用程式,并使用 node.js 和 express 創建了后端。 ..這就是我的檔案結構的樣子:

當我嘗試將它部署到 heroku 時,構建失敗給我這個錯誤
Could not find a required file.
Name: index.html
Searched in: /tmp/build_839c6cd8/public
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! proj@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the proj@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Some possible problems:
- Node version not specified in package.json
https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
為什么構建失敗?我究竟做錯了什么?
編輯:heroku 是否需要某種檔案結構?它似乎無法處理“構建”檔案夾..我在我的專案的根目錄(外部構建)中創建了一個公共目錄并將我的 index.html 移動到它,這解決了這個檔案的問題..現在當我嘗試部署它說
Could not find a required file.
Name: index.js
..所以現在“丟失”的檔案是js檔案..我現在該怎么辦?創建一個新的 src 目錄并將我的 js 移動到它?這是一些廢話……這是怎么回事?

uj5u.com熱心網友回復:
呃“固定嗎?”..似乎heroku試圖自己從create-react-app運行構建腳本,而不是像它們一樣運行我的專案檔案..我不得不從包中洗掉create-react-app腳本.json 檔案,現在一切都按預期作業..雖然我不明白為什么會發生這種情況,但如果任何有 heroku 背景的人都可以解釋它會很棒..
tl; dr:解決方案是從 package.json 中洗掉 create-react-app 腳本
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/395892.html
