Mern Deployment problem

Mern Deployment problem

Fyi, this is what I always use on heroku postbuild with CRA apps

"heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"

provided your client folder is in your root folder and created with CRA, delete any pre-existing build folders you may have in client as well, and delete all .lock files (yarn or package) , that works for me 90% of the time, but with the limited information that’s all I can say for now

1 Like

still not working. I want to email u my file if u have no problem. u may test it. Dereje1

[Dereje1] , i used your heroku-postbuild command. it works. it does not give error. but it is not showing react ui. this only shows ‘hello’ in browser which is in express for mere testing for first time.

probably because you are not serving the index.html file in your server app, you need , in your app, middleware with something like this,

app.use('/', express.static(path.join(__dirname, '../client/build')));

and in the bottom after all other routes, a wild card route with something like this

app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname, '../client/build', 'index.html'));

if you don’t have the path module you have to install it, if your build folder is somewhere else you have to properly address the directory, since I don’t see your app, I’m working blind folded here, not sure why you have a problem with pushing your code to github, but if you are working on full stack projects you should definitely be familiar with using github by now, at least it’s basic functionality.

1 Like

Ok, after seeing the files that @iiio sent me in DM, the main problem was that there were dual git controls set up , one in the root and one in the client, however heroku only works with the git control in the root, a separate git control in client does not allow the postbuild to go through, even though it looks like it is, so the solution is to completely delete the client git control and git init at the root, then heroku’s git control takes care of the rest, post-build and all…
Of course wild card and \ routes pointing to the CRA build folder in the client have to be also present at the correct places in the root server.

1 Like

You made my day, thanks you very much it work perfect :slight_smile: