bradtraversy / mern_shopping_list

Shopping List built with MERN and Redux
605 stars 437 forks source link

Build fails on deploying [Heroku] #39

Open kitecin opened 4 years ago

kitecin commented 4 years ago

Coming from this issue I opened as well in Stackoverflow

It works fine in the localhost, but when I try to push it to heroku I have this issue. I was following the Brad Traversy course about MERN but I got this and I can't continue.

This is my package.json

     "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"
        },
        "dependencies": {
            "body-parser": "^1.19.0",
            "concurrently": "^5.1.0",
            "express": "^4.17.1",
            "mongoose": "^5.9.7"
        },
        "devDependencies": {
            "cz-conventional-changelog": "^3.1.0",
            "nodemon": "^2.0.2"
        },
        "config": {
            "commitizen": {
                "path": "./node_modules/cz-conventional-changelog"
            }
        }

And this is the build error I'm getting.

        mbpdegobiaruben:MERN ShoppingList gchan$ git push heroku master
    Enumerating objects: 143, done.
    Counting objects: 100% (143/143), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (134/134), done.
    Writing objects: 100% (143/143), 208.32 KiB | 5.48 MiB/s, done.
    Total 143 (delta 63), reused 0 (delta 0)
    remote: Compressing source files... done.
    remote: Building source:
    remote: 
    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):  unspecified
    remote:        engines.npm (package.json):   unspecified (use default)
    remote:        
    remote:        Resolving node version 12.x...
    remote:        Downloading and installing node 12.16.2...
    remote:        Using default npm version: 6.14.4
    remote:        
    remote: -----> Installing dependencies
    remote:        Installing node modules
    remote:        
    remote:        > core-js@2.6.11 postinstall /tmp/build_33801817cc54d90aaf94bfb41e439539/node_modules/core-js
    remote:        > node -e "try{require('./postinstall')}catch(e){}"
    remote:        
    remote:        
    remote:        > nodemon@2.0.2 postinstall /tmp/build_33801817cc54d90aaf94bfb41e439539/node_modules/nodemon
    remote:        > node bin/postinstall || exit 0
    remote:        
    remote:        Love nodemon? You can now support the project via the open collective:
    remote:         > https://opencollective.com/nodemon/donate
    remote:        
    remote:        added 419 packages in 8.418s
    remote:        
    remote: -----> Build
    remote:        Running heroku-postbuild
    remote:        
    remote:        > mern-shoppinglist@1.0.0 heroku-postbuild /tmp/build_33801817cc54d90aaf94bfb41e439539
    remote:        > NPM_CONFIG_PRODUCTION= false npm install --prefix client && npm run build --prefix client
    remote:        
    remote: npm ERR! code ELIFECYCLE
    remote: npm ERR! errno 1
    remote: npm ERR! mern-shoppinglist@1.0.0 heroku-postbuild: `NPM_CONFIG_PRODUCTION= false npm install --prefix client && npm run build --prefix client`
    remote: npm ERR! Exit status 1
    remote: npm ERR! 
    remote: npm ERR! Failed at the mern-shoppinglist@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.O2wff/_logs/2020-04-16T05_41_17_476Z-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:        Some possible problems:
    remote:        
    remote:        - Node version not specified in package.json
    remote:          https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
    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 pacific-dawn-61320.
    remote: 
    To https://git.heroku.com/pacific-dawn-61320.git
     ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to 'https://git.heroku.com/pacific-dawn-61320.git'
alwaysakil commented 4 years ago

yup.. same error.. anything to change?

alwaysakil commented 4 years ago

Found the prob in my end.. The client folder had its own git repo.. so it doesnt get added to the main repo which is linked with heroku.. so I backed up the client folder and deleted the git stuff.. then put it back in this main folder and did a commit.. it added everything and it works now..

kitecin commented 4 years ago

Could you explain in detail how to do it, please? thank you buddy

youngheart12 commented 4 years ago

i am too having the same issue trying from mrng to get things but seems like nothing works still trying

alwaysakil commented 4 years ago

Could you explain in detail how to do it, please? thank you buddy

hey. when u create the react app , it comes with a .git folder and it is initialized.. so when u git init in the outside folder where both server + client folders are there, the client react folder does not get added to the git. now when u push to the heroku remote , the client folder is not at all pushed.. it is empty..
this was my issue.. dont know if its the same for you guys..

the solution what i did is to take a copy of the client folder and delete it inside this project.. then paste it back in without the git folder.. so this time it will be added to the main git and gets pushed to heroku...

cheers

dulerong commented 4 years ago

I just want to share my experience on this too, which is exactly what's written above by alwayskil.

Open up the client directory, not in visual studio but in windows folder, go to view and check show hidden folder, git folder will appear, delete it, cut and paste the entire client folder outside the main directory, then go back to command in visual studio, do the following

  1. Git add .
  2. Git commit -m "some comment"

After adding and committing without the client folder, cut and paste back the client folder to where it was, and do the following.

  1. Git init (not sure if this is necessary but I did it)
  2. heroku git:remote -a ... (the message for setting heroku remote)
  3. Git add .
  4. Git commit -m "some comment"
  5. Git push heroku master

As to why this error occurred I don't know, apparently it's got to do with having two git folders in main and client directory, each one gets created but perhaps intrinsically different? The solution seems to be getting rid of the git folder in the sub directory, keep the one in main directory, and do the above steps to make it work.