I built my application using create-react-app and created the backend using node.js and express..i used the build command to get a production version of the react app and made it work with my backend and everything was working fine on localhost ..this is how my file structure look like:
when i try to deploy it to heroku the build fails giving me this error
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! [email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] 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
why is the build failing? what am i doing wrong?
EDIT: does heroku require a certain file structure or something? it seems that it can't handle the "build" folder..i created a public dir in my project's root (outside build) and moved my index.html to it and this solved the problem for THIS file..now when i try to deploy it says
Could not find a required file.
Name: index.js
..so the file that's "missing" now is the js file..what should i do now? create a new src dir and move my js to it? this is some nonsense..what's going on?
uhh "fixed?"..seems heroku was trying to run the build script from create-react-app by itself instead of just running my project files as they are..i had to remove the create-react-app scripts from the package.json file and now everything works as intended.. although i don't understand why did that happen, if anyone with heroku background can explain that it would be great..
tl;dr: solution is to remove the create-react-app scripts from package.json