angular app working locally but not deployment failed on Heroku

Viewed 216

Angular app with spring boot app as backend working fine on localhost but when I try to deploy I get below deployment failed error. I stuck at this issue. I have tried so many solution but nothing worked. Here is my pakcage.json I added start in which mentioned server.js also added heroku-postbuild. package.json

"scripts": {
    "ng": "ng",
    "postinstall": "ngcc --properties es2015 browser module main --first-only",
    "start": "node server.js",
    "build": "ng build --prod --aot --build-optimizer --common-chunk --vendor-chunk --optimization --progress",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "heroku-postbuild": "ng build --configuration production"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^11.2.14",
    "@angular/cdk": "^11.2.13",
    "@angular/common": "^11.2.14",
    "@angular/compiler": "^11.2.14",
    "@angular/core": "^11.2.14",
    "@angular/forms": "^11.2.14",
    "@angular/localize": "^11.2.14",
    "@angular/material": "^11.2.13",
    "@angular/platform-browser": "^11.2.14",
    "@angular/platform-browser-dynamic": "^11.2.14",
    "@angular/router": "^11.2.14",
    "@coreui/angular": "~2.11.1",
    "@coreui/coreui": "^2.1.16",
    "@coreui/coreui-plugin-chartjs-custom-tooltips": "^1.3.1",
    "@coreui/icons": "^2.0.1",
    "@coreui/icons-angular": "1.0.0-alpha.3",
    "bootstrap": "^4.6.0",
    "chart.js": "^2.9.4",
    "classlist.js": "^1.1.20150312",
    "core-js": "^3.13.0",
    "express": "^4.17.1",
    "flag-icon-css": "^3.5.0",
    "font-awesome": "^4.7.0",
    "ng2-charts": "^2.4.2",
    "ngx-bootstrap": "^6.2.0",
    "ngx-perfect-scrollbar": "^10.1.1",
    "path": "^0.12.7",
    "rxjs": "^6.6.7",
    "simple-line-icons": "^2.5.5",
    "ts-helpers": "^1.1.2",
    "tslib": "^2.2.0",
    "web-animations-js": "^2.3.2",
    "zone.js": "~0.10.3",
    "typescript": "~4.0.5"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.1101.1",
    "@angular/cli": "^12.0.4",
    "@angular/compiler-cli": "^11.2.14",
    "@angular/language-service": "^11.2.14",
    "@types/jasmine": "^3.7.5",
    "@types/jasminewd2": "^2.0.9",
    "@types/node": "^14.17.1",
    "codelyzer": "^6.0.2",
    "jasmine-core": "~3.7.1",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~5.2.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.6.0",
    "protractor": "~7.0.0",
    "ts-node": "^8.10.2",
    "tslint": "~6.1.0",
    "typescript": "~4.0.5"
  },
  "engines": {
    "node": "12.18.2",
    "npm": "6.14.5"
  }

Below is server.js file which takes care of port and all Server.js code

//Install express server
const express = require('express');
const path = require('path');

const app = express();

// Serve only the static files form the dist directory
app.use(express.static('./dist/info-trace'));

app.get('/*', (req, res) =>
    res.sendFile('index.html', {root: 'dist/info-trace/'}),
);

// Start the app by listening on the default Heroku port
app.listen(process.env.PORT || 3000, function(){
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

Below is log errors on heroku logs Error logs on heroku

-----> Build
       Detected both "build" and "heroku-postbuild" scripts
       Running heroku-postbuild
       
       > info-trace@1.0.0 heroku-postbuild /tmp/build_2bc0074f
       > ng build --configuration production
       
npm ERR! code ELIFECYCLE
npm ERR! errno 3
npm ERR! info-trace@1.0.0 heroku-postbuild: `ng build --configuration production`
npm ERR! Exit status 3
npm ERR! 
npm ERR! Failed at the info-trace@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.ZMkzO/_logs/2021-06-11T17_16_58_035Z-debug.log
-----> Build failed

Is this configuration issue if yes then how to fix.

0 Answers
Related