0

I've been trying to push my react website to heroku and it wouldn't let me however i have successfully pushed it to github. i have updated my node version as well but nothing seems to work. there are similar questions on this site regarding the same issue and i also followed their steps but nothing seems to work

sh: 1: ng: not found
npm ERR! code ELIFECYCLE
npm ERR! syscall spawn
npm ERR! file sh
npm ERR! errno ENOENT
npm ERR! portfolio@1.0.0 heroku-postbuild: `ng build --prod`
npm ERR! spawn ENOENT
npm ERR! 
npm ERR! Failed at the portfolio@1.0.0 heroku-postbuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /tmp/npmcache.XmdM7/_logs/2020-02-21T00_18_42_925Z-debug.log
-----> Build failed

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       If you're stuck, please submit a ticket so we can help:
       https://help.heroku.com/

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed


here's my package.json file

{
  "name": "portfolio",
  "version": "1.0.0",
  "engines": {
    "node": "12.16.1",
    "npm": "6.13.4"
  },
  "description": "A clean, beautiful and responsive portfolio template for Developers!",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server --config webpack.dev.js --open",
    "build": "webpack --config webpack.prod.js",
    "heroku-postbuild": "ng build --prod"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/mkhawark/portfolio.git"
  },
  "keywords": [],
  "author": "Mohammad Khawar",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/mkhawark/portfolio/issues"
  },
  "homepage": "https://github.com/mkhawark/portfolio#readme",
  "devDependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "css-loader": "^3.4.1",
    "file-loader": "^5.0.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "mini-css-extract-plugin": "^0.9.0",
    "node-sass": "^4.13.0",
    "optimize-css-assets-webpack-plugin": "^5.0.3",
    "sass-loader": "^8.0.0",
    "style-loader": "^1.1.2",
    "webpack": "^4.41.5",
    "webpack-cli": "^3.3.10",
    "webpack-dev-server": "^3.10.1",
    "webpack-merge": "^4.2.2"
  },
  "dependencies": {
    "bootstrap": "^4.4.1",
    "jquery": "^3.4.1",
    "popper.js": "^1.16.0",
    "tilt.js": "^1.2.1"
  }
}

2 Answers2

0

Have you read through this: https://devcenter.heroku.com/articles/getting-started-with-nodejs

It looks like your start script is just launching the development server, but with heroku you have to serve up the actual build files.

you have to build the project then static serve the build folder using a simple server. Here is a sample setup in one of my projects, notice npm start just fires the express server index.js: https://github.com/mattberg88/genome-project/tree/heroku

Matt Berg
  • 499
  • 1
  • 4
  • 10
0

You can fix this by adding node_modules to your .gitignore page. You can check this link for more information: Fail to deploy node.js application to heroku

Let me know if this works for you :)

nourza
  • 2,215
  • 2
  • 16
  • 42