2

I'm getting this

Failed at the sequelize-demo@1.0.0 start script.

when deploying an express + react app. I think heroku is having an issue with concurrently.

enter image description here

What could i be doing wrong ? i referenced this, but the solution was a bit irrelevant to this application

Also referencing this

https://medium.freecodecamp.org/how-to-deploy-a-react-app-with-an-express-server-on-heroku-32244fe5a250

Root folder package.json

{
  "name": "sequelize-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "build": "concurrently \"cd client && npm run build\" \"npm build \"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "cd ./client && npm start ",
    "server-prod": "node app.js",
    "server": "nodemon app.js",
    "start": "concurrently --kill-others  \"npm run client\" \"npm run server\" ",
    "heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async": "^2.6.1",
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "concurrently": "^4.1.0",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-beta.3",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "express-flash": "0.0.2",
    "express-session": "^1.15.6",
    "foreman": "^3.0.1",
    "jsonwebtoken": "^8.4.0",
    "morgan": "^1.9.1",
    "nodemailer": "^5.1.1",
    "nodemon": "^1.18.9",
    "passport": "^0.4.0",
    "passport-github": "^1.1.0",
    "passport-github2": "^0.1.11",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "pg": "7.9.0",
    "pg-hstore": "^2.3.2",
    "sequelize": "^4.42.0",
    "sequelize-cli": "^5.4.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^6.1.2"
  }
}

client/package.json

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:8000",
  "dependencies": {
    "@material-ui/core": "^3.9.1",
    "@material-ui/icons": "^3.0.2",
    "axios": "^0.18.0",
    "history": "^4.7.2",
    "http-proxy-middleware": "^0.19.1",
    "jsonwebtoken": "^8.4.0",
    "jwt-decode": "^2.2.0",
    "material-ui-icons": "^1.0.0-beta.36",
    "moment": "^2.24.0",
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-redux": "^6.0.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "2.1.3",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0",
    "superagent": "^4.1.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "heroku-postbuild": "npm run build"
  },
  
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ],
  "devDependencies": {
    "dotenv": "^6.2.0"
  }
}

Profile

web: npm run start

Log

Users db and user table have been created

State changed from starting to up

Something is already running on port 32000.

npm run client exited with code 0

Sending SIGTERM to other processes..

npm run server exited with code SIGTERM `

npm ERR! sequelize-demo@1.0.0 start: concurrently --kill-others "npm run client" "npm run server"

npm ERR! Exit status 1 2019-04-11T07:26:41.326088+00:00 app[web.1]:

npm ERR! 2019-04-11T07:26:41.326282+00:00 app[web.1]:

npm ERR! Failed at the sequelize-demo@1.0.0 start script.

enter image description here

Community
  • 1
  • 1
randal
  • 1,272
  • 3
  • 23
  • 48
  • 1
    You can't run 2 servers at once on heroku, must create another app for the backend. – vitomadio Apr 11 '19 at 13:58
  • I think that when you deploy on the heroku you shoudl build your react files into bundle and server from node.js as public assets – Łukasz Szewczak Apr 11 '19 at 13:58
  • What would be a good stack overflow question or any other resource to look at ? So what you are saying is that concurrently wont work when deploying to heroku ? – randal Apr 11 '19 at 13:59
  • and their is a backend, check the repo. https://github.com/EliHood/mysequelizereact, let me know how you would change it to make it suitable to deploy – randal Apr 11 '19 at 14:01
  • the client is the front end, and the server is on app.js – randal Apr 11 '19 at 14:02

1 Answers1

1

Fixed it, i didn't have a react build.

Which is what i learned from

https://medium.freecodecamp.org/how-to-deploy-a-react-app-with-an-express-server-on-heroku-32244fe5a250

Now we need to make sure we have a build folder in our project before we push the project to the Heroku repository. Add the script below into your package.json file - author of the blog

So i did a npm run build on the client directory.

then changed my package.json to

{
  "name": "sequelize-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "client-install": "npm install --prefix client",
    "build": "concurrently \"cd client && npm run build\" \"npm build \"",
    "test": "echo \"Error: no test specified\" && exit 1",
    "client": "cd ./client && npm start ",
    "server-prod": "node app.js",
    "server": "nodemon app.js",
    "start": "node app.js",
    "start:dev": "concurrently --kill-others  \"npm run client\" \"npm run server\" ",
    "heroku-postbuild":"NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "async": "^2.6.1",
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "concurrently": "^4.1.0",
    "cookie-parser": "^1.4.3",
    "cookie-session": "^2.0.0-beta.3",
    "cors": "^2.8.5",
    "crypto": "^1.0.1",
    "dotenv": "^7.0.0",
    "express": "^4.16.4",
    "express-flash": "0.0.2",
    "express-session": "^1.15.6",
    "foreman": "^3.0.1",
    "jsonwebtoken": "^8.4.0",
    "morgan": "^1.9.1",
    "nodemailer": "^5.1.1",
    "nodemon": "^1.18.9",
    "passport": "^0.4.0",
    "passport-github": "^1.1.0",
    "passport-github2": "^0.1.11",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "pg": "7.9.0",
    "pg-hstore": "^2.3.2",
    "sequelize": "^4.42.0",
    "sequelize-cli": "^5.4.0"
  },
  "devDependencies": {
    "chai": "^4.2.0",
    "mocha": "^6.1.2"
  }
}

added this to app.js

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

if(process.env.NODE_ENV === 'production') {
  app.use(express.static(path.join(__dirname, 'client/build')));
  //
  app.get('*', (req, res) => {
    res.sendfile(path.join(__dirname = 'client/build/index.html'));
  })
}
//build mode
app.get('*', (req, res) => {
  res.sendFile(path.join(__dirname+'/client/public/index.html'));
})

Profile

web: npm start
randal
  • 1,272
  • 3
  • 23
  • 48