简体   繁体   English

为什么将我的 Angular 项目部署到 Heroku 时出现 ng not found 错误?

[英]Why am I getting an ng not found error when deploying my Angular project to Heroku?

My project layout looks like this:我的项目布局如下所示:

package.json (A)
index.js
client
> package.json (B)

with my outer package.json (A) looking like this:我的外部 package.json (A) 看起来像这样:

{
  "name": "---",
  "version": "1.0.0",
  "description": "---",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "build": "cd client && ng build --prod && cd .. && node index.js"
  },
  "repository": {
    "type": "git",
    "url": "---"
  },
  "author": "---",
  "license": "ISC",
  "bugs": {
    "url": "---"
  },
  "homepage": "---",
  "dependencies": {
    "axios": "^0.19.2",
    "cors": "^2.8.5",
    "dotenv": "^8.2.0",
    "express": "^4.17.1",
    "mongoose": "^5.9.14"
  }
}

while the package.json (B) inside the client folder that holds the angular project looks like this:而包含 angular 项目的客户端文件夹中的 package.json (B) 看起来像这样:

{
  "name": "client",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/cli": "~9.0.6",
    "@angular/compiler-cli": "~9.0.6",
    "@angular/animations": "~9.0.6",
    "@angular/common": "~9.0.6",
    "@angular/compiler": "~9.0.6",
    "@angular/core": "~9.0.6",
    "@angular/fire": "^6.0.0",
    "@angular/forms": "~9.0.6",
    "@angular/platform-browser": "~9.0.6",
    "@angular/platform-browser-dynamic": "~9.0.6",
    "@angular/router": "~9.0.6",
    "firebase": "^7.14.4",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.900.6",
    "@angular/cli": "~9.0.6",
    "@angular/compiler-cli": "~9.0.6",
    "@angular/language-service": "~9.0.6",
    "@types/node": "^12.11.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~5.18.0",
    "typescript": "~3.7.5"
  }
}

Looking up other threads that have asked similar things, most of them said that I needed to move the @angular/cli and @angular/compiler-cli from devDependencies to dependencies, which is what I did.查找其他问过类似问题的线程,他们中的大多数人都说我需要将 @angular/cli 和 @angular/compiler-cli 从 devDependencies 移动到依赖项,这就是我所做的。

However, when Heroku runs the script但是,当 Heroku 运行脚本时

"build": "cd client && ng build --prod && cd .. && node index.js"

I'm not sure why I keep getting the error that ng was not found.我不确定为什么我不断收到未找到 ng 的错误。 Another thing I tried was to add the preinstall script to package.json (A)我尝试的另一件事是将预安装脚本添加到 package.json (A)

"preinstall": "npm install -g angular-cli"

which removed the ng not found error, but instead I got an error saying that the build command would only work inside of an angular-cli project, which is making me think that maybe the change directory isn't working?它删除了 ng not found 错误,但是我收到一个错误,说 build 命令只能在 angular-cli 项目中工作,这让我认为更改目录可能不起作用? This is really confusing to me, because npm run build works fine for me...这真的让我很困惑,因为 npm 运行构建对我来说很好......

I messed around a bit and finally got it to work.我搞砸了一点,终于让它工作了。 My solution was to change my package.json (A) scripts to我的解决方案是将我的 package.json (A) 脚本更改为

"scripts": {
    "start": "node index.js",
    "build": "cd client && npm install && npm run build --prod"
  },

and to move literally everything in devDependencies in package.json (B) into the dependencies folder.并将 package.json (B) 中的 devDependencies 中的所有内容移动到依赖项文件夹中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Angular 应用程序部署到 Heroku 时出现“未找到”错误 - 'Not Found' error when deploying Angular app to Heroku 在我的angular2应用程序上运行npm install和ng serve时,出现以下错误 - I am getting an below error when i run npm install and ng serve on my angular2 application 当我使用托管在 heroku 上的 AWS 应用程序中的数据库部署我的反应节点时,“未找到” - “Not found” when I am deploying my react node with database hosted in AWS application on heroku 在heroku上部署Angular项目时出错 - Error deploying Angular project on heroku 为什么在 Heroku 上部署 nodejs 应用程序时出现此应用程序错误? - why am i getting this application error while deploying nodejs app on Heroku? 部署到heroku时,出现以下错误日志 - While deploying to heroku , I am getting the following error log 为什么在我的无服务器项目上运行 npm 构建时出现此 UnhandledPromiseRejectionWarning 错误? - Why am I getting this UnhandledPromiseRejectionWarning error when running npm build on my serverless project? webpack:未找到 - 将我的应用程序部署到 heroku 时 - webpack: not found -When deploying my app to heroku 将我的项目上传到 Heroku 时出现此错误。 我正在使用 MapBox 和 node.js - I am getting this error while uploading my project to Heroku. I am using MapBox and node.js 为什么在部署 Google Cloud NodeJS 应用程序时出现 404 错误? - Why am I getting a 404 Error when Deploying Google Cloud NodeJS Application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM