Heroku deploy issue sh: 1: ng: not found?

左心房为你撑大大i 提交于 2020-06-27 09:34:10

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/46885249/heroku-deploy-issue-sh-1-ng-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!