how to fix npm ERR! code ELIFECYCLE (heroku)

Viewed 23

I'm currently working on a project since i've been teaching myself Angular over the past couple weeks. I wrote up my code, created what I thought I needed for deploying on heroku and tried to deploy it. I received the following error

-----> Build
   Detected both "build" and "heroku-postbuild" scripts
   Running heroku-postbuild
   
   > purposefularmament@0.0.0 heroku-postbuild /tmp/build_2c8456a0
   > ng build --configuration production
   npm ERR! code ELIFECYCLE
   npm ERR! errno 3
   npm ERR! purposefularmament@0.0.0 heroku-postbuild: `ng build --configuration 
   production`
   npm ERR! Exit status 3
   npm ERR! 
   npm ERR! Failed at the purposefularmament@0.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.JjS0Q/_logs/2022-09-23T14_54_55_966Z-debug.log
   -----> Build failed

after doing some research I only found that this error is caused by an issue with my npm install. I deleted my node_modules file and removed package-lock.json, cleared the npm cache and then reinstalled npm. I repushed the code and Im still getting this same error.

Any suggestions?

Here is my package.json and server.js files

{
"name": "purposefularmament",
"version": "0.0.0",
 "scripts": {
  "ng": "ng",
  "start": "node server.js",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e",
  "heroku-postbuild": "ng build --configuration production"
},
 "private": true,
   "dependencies": {
     "@angular/animations": "~11.1.2",
     "@angular/cli": "^14.2.3",
     "@angular/common": "~11.1.2",
     "@angular/compiler": "~11.1.2",
     "@angular/compiler-cli": "^11.2.14",
     "@angular/core": "~11.1.2",
     "@angular/forms": "~11.1.2",
     "@angular/platform-browser": "~11.1.2",
     "@angular/platform-browser-dynamic": "~11.1.2",
     "@angular/router": "~11.1.2",
     "bootstrap": "^5.2.1",
     "bootstrap-icons": "^1.9.1",
     "bulma": "^0.9.4",
     "express": "^4.18.1",
     "grunt-express": "^1.4.1",
     "node": "^14.15.0",
     "path": "^0.12.7",
     "rxjs": "~6.6.0",
     "tslib": "^2.0.0",
     "typescript": "~4.1.2",
     "zone.js": "~0.11.3"
 },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.1101.4",
    "@angular/cli": "^14.2.3",
    "@angular/compiler-cli": "^11.2.14",
    "@types/jasmine": "~3.6.0",
    "@types/node": "^12.11.1",
    "autoprefixer": "^10.4.8",
    "codelyzer": "^6.0.0",
    "jasmine-core": "~3.6.0",
    "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.5.0",
    "postcss": "^8.4.16",
    "protractor": "~7.0.0",
    "tailwindcss": "^3.1.8",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~4.1.2"
 },
  "engines": {
    "node": "14.15.0",
    "npm": "6.14.13"
 }
}

and server.js

    //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(__dirname + '/dist/purposefularmament'));

    app.get('/*', function(req,res) {
       res.sendFile('index.html', {root: 'dist/purposefularmament/'});
    });
    
    // Start the app by listening on the default Heroku port
    app.listen(process.env.PORT || 8080);
   
1 Answers

Welp I spoke too soon, for those of you how care I fixed the issue by updating node.js to the newest latest version. I was lead to believe that both heroku and my local system should use the same node version. For whatever reason my version was behind. After adjusting for the new node version I repushed and everything worked.

Related