7

Failed Heroku deploy. Been looking at other similar stack overflow posts and changing package.json file trying solutions that have worked for others with no luck. I am not sure if this is a port issue, or a package.json issue or something completely different. Any help, tips or advice is greatly appreciated!

Heroku logs: 

2019-02-09T08:32:56.609533+00:00 heroku[web.1]: State changed from crashed to starting
2019-02-09T08:33:00.956199+00:00 heroku[web.1]: Starting process with command `npm start`
2019-02-09T08:33:03.430137+00:00 heroku[web.1]: State changed from starting to crashed
2019-02-09T08:33:03.257739+00:00 app[web.1]: 
2019-02-09T08:33:03.257781+00:00 app[web.1]: > the-lottery-genie-mean@0.0.0 start /app
2019-02-09T08:33:03.257783+00:00 app[web.1]: > ng serve
2019-02-09T08:33:03.257784+00:00 app[web.1]: 
2019-02-09T08:33:03.294426+00:00 app[web.1]: sh: 1: ng: not found
2019-02-09T08:33:03.304958+00:00 app[web.1]: npm ERR! file sh
2019-02-09T08:33:03.305986+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-02-09T08:33:03.306367+00:00 app[web.1]: npm ERR! errno ENOENT
2019-02-09T08:33:03.309015+00:00 app[web.1]: npm ERR! syscall spawn
2019-02-09T08:33:03.310700+00:00 app[web.1]: npm ERR! the-lottery-genie-mean@0.0.0 start: `ng serve`
2019-02-09T08:33:03.310912+00:00 app[web.1]: npm ERR! spawn ENOENT
2019-02-09T08:33:03.311266+00:00 app[web.1]: npm ERR! 
2019-02-09T08:33:03.311514+00:00 app[web.1]: npm ERR! Failed at the the-lottery-genie-mean@0.0.0 start script.
2019-02-09T08:33:03.314421+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-02-09T08:33:03.324652+00:00 app[web.1]: 
2019-02-09T08:33:03.324892+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2019-02-09T08:33:03.325013+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2019-02-09T08_33_03_316Z-debug.log
2019-02-09T08:33:03.411224+00:00 heroku[web.1]: Process exited with status 1 

package.json: 

{
  "name": "the-lottery-genie-mean",
  "version": "0.0.0",
  "scripts": {
    "preinstall": "npm link @angular/cli ",
    "heroku-postbuild": "ng build --prod",
    "postinstall": "",
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "^7.1.4",
    "@angular/compiler-cli": "~7.0.0",
    "@angular/animations": "~7.0.0",
    "@angular/common": "~7.0.0",
    "@angular/compiler": "~7.0.0",
    "@angular/core": "~7.0.0",
    "@angular/forms": "~7.0.0",
    "@angular/http": "~7.0.0",
    "@angular/platform-browser": "~7.0.0",
    "@angular/platform-browser-dynamic": "~7.0.0",
    "@angular/router": "~7.0.0",
    "core-js": "^2.5.4",
    "json": "^9.0.6",
    "rxjs": "~6.3.3",
    "zone.js": "~0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.1",
    "@angular/language-service": "~7.0.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.1"
  },
  "engines": {
    "node": "10.15.1",
    "npm": "6.4.1"
  }
}

server.js file

app.listen(PORT, '0.0.0.0', function () {
console.log("Node app is running at localhost:" + app.get('port'));

})

Alexander Mazilu
  • 43
  • 1
  • 1
  • 8
  • heroku build log: + @angular/cli@7.3.1 remote: added 295 packages from 179 contributors in 14.433s remote: /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/@angular/cli -> /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/.heroku/node/lib/node_modules/@angular/cli remote: npm ERR! path /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/.staging/@angular/cli-cf0b324f/node_modules/@schematics/angular – Alexander Mazilu Feb 12 '19 at 00:08
  • have you checked this? https://stackoverflow.com/questions/37227794/ng-command-not-found-while-creating-new-project-using-angular-cli – r7r Jul 27 '20 at 11:28

4 Answers4

6

Did you check the debug log here /app/.npm/_logs/2019-02-09T08_33_03_316Z-debug.log ?

I suggest looking into the debug log first to get us more details to solve the problem.

UPDATE

Its an H10 error. "heroku[router]: at=error code=H10 desc="App crashed"
method=GET path="/favicon.ico" host=angular-lottery-genie.herokuapp.com
request_id=30e63a79-c395-4d2a-9987-938bcc350629 fwd="50.250.113.70" dyno=
connect= service= status=503 bytes= protocol=https"

Your app crashed. Here are some things you can do:

1.) Restart heroku. You should have heroku CLI installed. Here's the link: Heroku CLI Install . And run heroku restart on your terminal.

2.) Use port that Heroku dynamically sets which can be accessed usually at process.env.PORT, and set your desired port as backup:

app.listen(process.env.PORT || 3000, function(){
  console.log("Node app is running at localhost:" + app.get('port'));
});

3.) Try to check your node and npm version by typing in your terminal:

node --version
npm --version

And update the node and npm versions indicated under your package.json file:

"engines": {
  "node": "10.15.1",
  "npm": "6.4.1"
}

Another UPDATE for your questions:

npm ERR! enoent ENOENT: no such file or directory

These errors are usually related to corruption or incompatibility of packages. What you can do:

1.) Make sure no other instances of node are running in the backgound and retry your npm command.

2.) Delete the node_modules directory and package-lock.json (if you have any). Reinstall packages running npm install (or any command you're using to install the packages) in your terminal inside your project directory.

3.) Upgrade node to the latest version, delete node_modules directory and package-lock.json, and reinstall the packages.

4.) If npm still does not work for you, try yarn package manager (Yarn).

5.) If packages installation still fail, check the error logs file for a detailed report of the error.

Hope this helps!

Community
  • 1
  • 1
  • Can't comment for I am still a newbie, sorry. Can you add the debug log and I'll see what I can do to help. :) – Sarah Dominguez Perea Feb 09 '19 at 08:48
  • heroku build log: + @angular/cli@7.3.1 remote: added 295 packages from 179 contributors in 14.433s remote: /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/@angular/cli -> /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/.heroku/node/lib/node_modules/@angular/cli remote: npm ERR! path /tmp/build_65b96372ee3e3abaf6f27c4e836c1557/node_modules/.staging/@angular/cli-cf0b324f/node_modules/@schematics/angular I cant find where this file is. – Alexander Mazilu Feb 12 '19 at 00:09
  • Its an H10 error. "heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=angular-lottery-genie.herokuapp.com request_id=30e63a79-c395-4d2a-9987-938bcc350629 fwd="50.250.113.70" dyno= connect= service= status=503 bytes= protocol=https" – Alexander Mazilu Feb 12 '19 at 02:01
  • In my case, I need define PORT outside listen(). Ex: `const PORT = process.env.PORT || 3000;` then `app.listen(PORT, cb)` – Thai Ha Feb 12 '19 at 03:01
  • Thanks I noticed when trying to define an older version of node in the engines tab, it continued to use 10.15.1 which seemed strange. I noticed when I do heroku --version, Heroku cli comes with its own version of node (11.9.0), which I tried changing to match in the package.json. Also another build log npm ERR! enoent ENOENT: no such file or directory, rename '/tmp/build_a71fe5a93776d909b8eafd56852942f0/node_modules/.staging/@angular/cli-cc14dd1a/node_modules/@schematics/angular' -> '/tmp/build_a71fe5a93776d909b8eafd56852942f0/node_modules/.staging/@schematics/angular-d146d3ec' – Alexander Mazilu Feb 12 '19 at 05:25
  • Hi @AlexanderMazilu, I updated my answer to answer your questions. Hope it will be of any help. :) – Sarah Dominguez Perea Feb 12 '19 at 06:09
3

You might need to add the devkit/builder, make sure its in the right sequence. I added it in bold so make sure if you are gonna copy paste to remove the asterix from the beginning and end.

"@angular/cli": "^7.1.4",
"@angular/compiler-cli": "~7.0.0",
"@angular/animations": "~7.0.0",
"@angular/common": "~7.0.0",
"@angular/compiler": "~7.0.0",
"@angular/core": "~7.0.0",
"@angular/forms": "~7.0.0",
"@angular/http": "~7.0.0",
"@angular/platform-browser": "~7.0.0",
"@angular/platform-browser-dynamic": "~7.0.0",
"@angular/router": "~7.0.0",
**"@angular-devkit/build-angular": "^0.13.1",
"@angular/language-service": "~7.0.0",**
"core-js": "^2.5.4",
"json": "^9.0.6",
"rxjs": "~6.3.3",
"zone.js": "~0.8.26"
Pari Baker
  • 696
  • 4
  • 19
  • I belive it needs the devkit for the build (as you can see from the angular.json) I also am pretty sure that heroku doesn't install dev dependencies by default. So when it installs everything it goes to look for that module and can't find it. – Pari Baker Feb 26 '19 at 20:29
2

In my experience, the deployment of an app that works locally is not always straightforward in Heroku. There are several cases like this in StackOverflow without a definitive solution, specially related to "'library' not found". For someone with a similar problem (trying to deploy AngularJS in Heroku) I would recommend check first functional tutorials like these:

Alex
  • 428
  • 5
  • 8
0

move some devDependencies to dependencies (angular 9 example)

 npm i @angular/cli @angular-devkit/build-angular @angular/compiler-cli typescript --save-prod

or set NPM_CONFIG_PRODUCTION to false

here is an answer to similar question

ya_dimon
  • 3,483
  • 3
  • 31
  • 42