Mern Deployment problem

Hello,
I am trying to deploy a mern app in heroku. But I cannot deploy it. It works fine but at the very last it says,

remote:  !     Push rejected, failed to compile Node.js app. 
! [remote rejected] master -> master (pre-receive hook declined) 
error: failed to push some refs to [git url] 

please help me .

post your package.json, also are you doing a post-build on heroku? or is your client pre-built before your deployment. I also delete all .lock files before deploying and I found that heroku doesn’t play well with yarn as well as it does with npm.

This is my package.json file.

{
  "name": "mernuser",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client":"npm start --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\"",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.3",
    "concurrently": "^4.1.0",
    "express": "^4.16.4",
    "jsonwebtoken": "^8.4.0",
    "mongoose": "^5.4.9",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "validator": "^10.11.0"
  },
  "engines": {
    "node": "10.13.0"
  }
}

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

ok bro. But i cannot solve my problem yet.

inside your root folder type git remote -v
and post the result here, also post your entire log from when you started the deploy including the command you used to deploy, the error you are getting seems git related , but your post-build command looks also strange

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:        > mernuser@1.0.0 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! mernuser@1.0.0 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 mernuser@1.0.0 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