Mern Deployment problem

Mern Deployment problem
0

note also --prefix is good for changing directories in linux, if you are on windows need to use cd

I’m not sure, but… You don’t seem to have devDependencies for nodemon? Try to add it in the package.json and see if it works.

heroku follows npm start script which is using node per the package.json, he’s using nodemon only for dev mode running the server script

I was also wondering the same thing… as it’s only for development.

Maybe this will help: https://stackoverflow.com/questions/18660474/push-rejected-failed-to-compile-node-js-app-heroku

remote: -----> Node.js app detected
remote:
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:        NODE_VERBOSE=false
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  10.13.0
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 10.13.0...
remote:        Downloading and installing node 10.13.0...
remote:        Using default npm version: 6.4.1
remote:
remote: -----> Building dependencies
remote:        Installing node modules (package.json)
remote:        added 174 packages from 108 contributors and audited 331 packages in 6.553s
remote:        found 0 vulnerabilities
remote:
remote:        Running heroku-postbuild
remote:
remote:        > [email protected] heroku-postbuild /tmp/build_cb624059487c43463f1d03ecd2377f54
remote:        > NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client
remote:
remote:        up to date in 0.436s
remote:        found 0 vulnerabilities
remote:
remote: npm ERR! path /tmp/build_cb624059487c43463f1d03ecd2377f54/client/package.json
remote: npm ERR! code ENOENT
remote: npm ERR! errno -2
remote: npm ERR! syscall open
remote: npm ERR! enoent ENOENT: no such file or directory, open '/tmp/build_cb624059487c43463f1d03ecd2377f54/client/package.json'
remote: npm ERR! enoent This is related to npm not being able to find a file.
remote: npm ERR! enoent
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.CokUm/_logs/2019-02-10T07_49_35_747Z-debug.log
remote: npm ERR! code ELIFECYCLE
remote: npm ERR! errno 254
remote: npm ERR! [email protected] heroku-postbuild: `NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client`
remote: npm ERR! Exit status 254
remote: npm ERR!
remote: npm ERR! Failed at the [email protected] heroku-postbuild script.
remote: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
remote:
remote: npm ERR! A complete log of this run can be found in:
remote: npm ERR!     /tmp/npmcache.CokUm/_logs/2019-02-10T07_49_35_761Z-debug.log
remote:
remote: -----> Build failed
remote:
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to immense-reaches-82524.
remote:
To https://git.heroku.com/immense-reaches-82524.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/immense-reaches-82524.git'

[husseyexplores].tried that link yesterday.
[Dereje1], it is full result after master push in heroku.

Do you have a valid Procfile? https://devcenter.heroku.com/articles/procfile

And did you try all these steps mentioned here? https://devcenter.heroku.com/articles/troubleshooting-node-deploys

^ looks like this is your problem, it is looking for the client package.json to build in the wrong place, or at least it can’t resolve the path some how, post your git clone link and i can attempt doing a deploy later

i do not have github yet. but i can send u my file in email if u want.

but you have git on your machine right?

no i do not have procfile here. i had deployed a pure node app in heroku which doesn’t have procfile. so i think it may work without procfile

yes. I have in windows machine.

Well, add the Procfile then. This is a requirement only for Heroku.

It is also included in their sample node app: https://github.com/heroku/node-js-sample

If that doesn’t solve the issue, the last thing I could think of is disabling the cache.

I can’t say anything more without trying to deploy it myself. Goodluck!

(Edit: It’s been a while since I’ve deployed on Heroku. Last time I deployed it a year back, Profile was required. I’m not sue if it is still a requirement. Please correct me if I’m wrong.
I’m wrong here I believe, Procfile isn’t required.)

1 Like

yeah , you don’t really need procfile to run a node app on heroku, well it is hard to troubleshoot without testing your files, I’d open a github account and push your files there, you’ll need a github account sooner or later anyways

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: