13

I'm facing some issues while running app in heroku.

Log:

 2017-10-22T20:41:16.421991+00:00 app[web.1]: npm ERR! errno ENOENT
 2017-10-22T20:41:16.411165+00:00 app[web.1]: > ng serve
 2017-10-22T20:41:16.411149+00:00 app[web.1]: 
 2017-10-22T20:41:16.421630+00:00 app[web.1]: npm ERR! file sh
 2017-10-22T20:41:16.411165+00:00 app[web.1]: 
 2017-10-22T20:41:16.416314+00:00 app[web.1]: sh: 1: ng: not found

package.json:

"scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
},

Env:

Angular 4, and I'm not using NodeJS express. I have deployed app in Heroku.

boop_the_snoot
  • 3,209
  • 4
  • 33
  • 44
Kanna
  • 990
  • 1
  • 11
  • 30
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Oct 23 '17 at 10:29

2 Answers2

8

you can let heroku build your dev dependencies by setting environment: NPM_CONFIG_PRODUCTION to false. (how?)


or you can move (angular 9)
@angular/cli,
@angular/compiler-cli
@angular-devkit/build-angular
typescript
from devDependencies to dependencies.

so, run:

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

or with your versions, if you specified some. e.g.:

 npm i @angular/cli@9.1.x @angular-devkit/build-angular@0.901.x @angular/compiler-cli@9.1.x typescript@3.8.x --save-prod

issue by github

ya_dimon
  • 3,483
  • 3
  • 31
  • 42
  • Don't use `ng serve` in production. Instead, deploy a production build. – ChrisGPT was on strike Jan 10 '23 at 13:16
  • @Chris ahm you probably misunderstood the answer, nobody suggests to use `ng serve` in production. Mostly cases its about `ng build` to not to commit the compiled code in git and to use environment variables of server for building there. – ya_dimon Jan 11 '23 at 23:53
  • Perhaps _you_ misunderstand. Heroku runs your `build` script automatically as part of its build phase. During that phase, `devDependencies` are available. There is no need to move them to `dependencies`. After the build phase is done, `devDependencies` are pruned. The correct solution is to make sure your `build` script does a production build, and to host the built files as static assets. If there are runtime errors about `ng`, this was not done correctly. – ChrisGPT was on strike Jan 12 '23 at 00:16
  • @Chris looks good, i think at the moment of question/answer heroku did not used devDeps while build `ng build` (look at gh issue). Now maybe it works like in heroku doc. *BUT* there is still no suggestion to use `ng serve` in prod in the answer‍♂️, thats my point of comment. – ya_dimon Jan 12 '23 at 16:14
  • Heroku's Node.js buildpack _definitely_ installed dev dependencies and made them available during the build phase in 2020 and I'm pretty sure it did in 2017 as well. That has been the case for as long as I can remember. The only reason to move something from dev dependencies to dependencies is to make it available at runtime. Telling somebody to do that is the same as telling them to use `ng` to serve their application. – ChrisGPT was on strike Jan 13 '23 at 00:50
3

In production environment, Angular code is deployed as static code.

Simply run:

ng build --prod --aot

Deploy the dist folder generated as the static website.

Refer: https://www.youtube.com/watch?v=jw1RtGJKIbw

nilansh bansal
  • 1,404
  • 1
  • 12
  • 23