2

I am trying to push a Reactjs application to Heroku.

This is my package.json file:

{
  "name": "redux-simple-starter",
  "version": "1.0.0",
  "description": "Simple starter package for Redux with React and Babel support",
  "main": "index.js",
  "repository": "[email protected]:ldco2016/efUtube.git",
  "scripts": {
    "dev": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "postinstall": "webpack -p",
    "start": "node server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "jquery": "3.0.0",
    "jsdom": "^8.1.0",
    "mocha": "^2.4.5",
    "react-addons-test-utils": "^0.14.7",
    "webpack": "^1.12.9",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "babel-preset-stage-1": "^6.1.18",
    "lodash": "^3.10.1",
    "node": "9.4.0",
    "react": "^0.14.3",
    "react-dom": "^0.14.3",
    "react-redux": "^4.0.0",
    "react-router": "^2.0.1",
    "redux": "^3.0.4",
    "youtube-api-search": "0.0.5"
  }
}

I conducted an:

npm install -g webpack as well as webpack -p

I created a server.js file and completed it with this code:

const express = require('express');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();

app.use(express.static(__dirname));

app.get('*', (req, res) => {
  res.sendFile(path.resolve(__dirname, 'index.html'))
});

app.listen(port);
console.log('Server started');

It works locally when I run node server.js in command line, but when commiting and pushing changes and running:

git push heroku master I repeatedly get this error:

remote: /app/tmp/buildpacks/19862b8792e84bd8421ded4660b92dfd1c41d92e19ac0b38c90301adc8ae3e0bd512fa01998af18fc2f0d31a157e9c82e8fdceba1a05e5d29adb8dc2bfaf08e1/lib/failure.sh: line 282: greq: command not found
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:
2
  • The best way that I have found to do this is by using this buildpack github.com/mars/create-react-app-buildpack Commented Jan 27, 2018 at 5:10
  • @Swapnil, I was just researching that right before you wrote it. You may be right, it is the only solution I have seen thus far. Commented Jan 27, 2018 at 5:17

1 Answer 1

2

Check your node version with this command node -v and npm version with this command npm -v, then specify the node and npm version in you package.json like this:

"engines": { "node": "8.1.x", "npm": "5.0.x" },

Make sure you specify it before the list of dependencies and devDependencies.

Sign up to request clarification or add additional context in comments.

4 Comments

It looks like I also had to remove the "postinstall":"webpack -p"
I'm glad this help, yeah not sure you need it, why did you put it there before
I was watching a tutorial that said I needed it, but I was actually getting an error as a result. I also needed to install express but now I have a different problem where it is successfully pushed to heroku but I get a blank screen on the browser. I am working on resolving that one now.
Yeah I saw where you posted the error and i actually reply to what you can do to get it solved. Kindly check: stackoverflow.com/questions/48493781/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.