0

I'm trying to deploy a React on Node project I was working on and am running into some issues and I'm not certain why. Below is some information pulled from the log:

2018-02-11T00:12:22.875338+00:00 app[web.1]: > dmdb@1.0.0 start /app
2018-02-11T00:12:22.875340+00:00 app[web.1]: > node server.js
2018-02-11T00:12:22.875341+00:00 app[web.1]: 
2018-02-11T00:12:23.315310+00:00 heroku[web.1]: State changed from starting to crashed
2018-02-11T00:12:23.299113+00:00 heroku[web.1]: Process exited with status 1
2018-02-11T00:13:23.976931+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=dmdb1.herokuapp.com request_id=8d37e10b-6999-4a2f-82bb-f3e724bf1c4e fwd="108.14.98.161" dyno= connect= service= status=503 bytes= protocol=https

Based on what the log shows, it seems like there's an issue with the start script in my package.json file, but I'm not sure why since I've used a similar one for another project I've deployed successfully. I did some research on this and I believe my Server.js file is configured and the ports are set up properly, I removed devdependencies and confirmed it works locally but not deployed, and I've got my SECRET_KEY set up in the vars since this has auth set up. Below is how I have my ports set up, and what my package.json file looks like on the backend. If anybody could please provide some insight I'd greatly appreciate it. If there's any additional information I can provide please let me know and I'll do so ASAP.

Ports from Server.js:

//app listening on port 1337
const PORT = process.env.PORT || 1337;
app.listen(PORT, () => {
    console.log(`LISTENING ON PORT ${PORT}`)
})

Updated Package.json from Backside:

{
  "name": "dmdb",
  "version": "1.0.0",
  "description": "",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js",
    "dev": "nodemon server.js",
    "debugger": "DEBUG=*:* nodemon server.js",
    "prod": "NODE_ENV=production node server.js",
    "deploy": "cd client && yarn build && cp -a ./build/ ../public/",
    "heroku-postbuid" : "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
  },
  "engines": {
    "node": "8.5.0",
    "yarn": "1.3.2"
  },  
  "author": "Dan Levenson",
  "license": "MIT",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.18.2",
    "cookie-parser": "^1.4.3",
    "cors": "^2.8.4",
    "dotenv": "^4.0.0",
    "ejs": "^2.5.7",
    "ejs-lint": "^0.3.0",
    "express": "^4.16.2",
    "express-session": "^1.15.6",
    "isomorphic-fetch": "^2.2.1",
    "method-override": "^2.3.10",
    "morgan": "^1.9.0",
    "passport": "^0.4.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "pg-promise": "^7.0.3"
  }
}

Thanks in advance!

Editing post to include Package.JSON from client:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-router-dom": "^4.2.2",
    "react-scripts": "1.1.0",
    "reactstrap": "^5.0.0-beta"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:3001"
}

Adding Build Log:

-----> Node.js app detected
-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NPM_CONFIG_PRODUCTION=true
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true
-----> Installing binaries
       engines.node (package.json):  8.5.0
       engines.npm (package.json):   unspecified (use default)
       engines.yarn (package.json):  1.3.2

       Resolving node version 8.5.0...
       Downloading and installing node 8.5.0...
       Using default npm version: 5.3.0
       Resolving yarn version 1.3.2...
       Downloading and installing yarn (1.3.2)...
       Installed yarn 1.3.2
-----> Restoring cache
       Loading 2 from cacheDirectories (default):
       - node_modules
       - bower_components (not cached - skipping)
-----> Building dependencies
       Installing node modules (yarn.lock)
       yarn install v1.3.2
       [1/4] Resolving packages...
       success Already up-to-date.
       Done in 0.30s.
-----> Caching build
       Clearing previous node cache
       Saving 2 cacheDirectories (default):
       - node_modules
       - bower_components (nothing to cache)
-----> Build succeeded!
-----> Discovering process types
       Procfile declares types -> web
-----> Compressing...
       Done: 20.7M
-----> Launching...
       Released v12
       https://dmdb-1.herokuapp.com/ deployed to Heroku
Daniel
  • 155
  • 2
  • 12
  • How are you building your client on Heroku? From what you posted, Heroku would only be running your npm start script. So perhaps you need to add a heroku-postbuild script to run what you currently have in "deploy"? See https://stackoverflow.com/questions/48531545/heroku-failed-at-the-build-script-but-heroku-local-web-is-fine/48538277#48538277. – Yoni Rabinovitch Feb 11 '18 at 08:12
  • Thanks for the tip, I've tried adding a postbuild script similar to the post you had linked but am still getting the same error. I took another look through the logs and it appears that some of my models may not be detected properly: Error: Cannot find module '../../models/user.js' Do you think this could somehow be related? – Daniel Feb 11 '18 at 13:30
  • Please post your updated package.jsons for both server and client directories. – Yoni Rabinovitch Feb 12 '18 at 06:47
  • Sorry for delay, just posted updates. – Daniel Feb 12 '18 at 19:26
  • You have a typo in your package.json scripts: "heroku-postbuid" should be "heroku-postbuild". After you fix that, if you still have problems, post your build log. – Yoni Rabinovitch Feb 13 '18 at 10:03
  • Made the change and it deployed without issue but I'm still getting the same error when I try to launch the app through Heroku. I've updated the post with the Build Log, let me know if you need the error logs or anything else. Thanks for all your help with this btw! – Daniel Feb 13 '18 at 14:59

2 Answers2

0

Rebuilt app using NPM instead of Yarn and it deployed without issue and is running fine now. Thanks for the help!

Daniel
  • 155
  • 2
  • 12
0

THIS SOLUTION IS FOR GO .

When you deploy an app through heroku, it does not allow you to specify the port number.
In other words, you can not specify your web service's port number as 8000 or something else, heroku decides the port number in runtime.
so, you can not use the following code:

    log.Fatal(http.ListenAndServe(":8000", router))

What you can do is, getting the runtime port of heroku.
In short, just use the following code:

    log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))
Celik
  • 2,311
  • 2
  • 32
  • 54