【发布时间】:2022-01-25 20:59:24
【问题描述】:
我使用 create-react-app 构建了我的应用程序,并使用 node.js 和 express 创建了后端。我使用 build 命令获取了 react 应用程序的生产版本,并使其与我的后端一起工作,一切正常在本地主机上很好..这就是我的文件结构的样子:
当我尝试将其部署到 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
..so 现在“丢失”的文件是 js 文件..我现在该怎么办?创建一个新的 src 目录并将我的 js 移动到它?这是一些废话..这是怎么回事?
【问题讨论】:
标签: node.js heroku create-react-app