简体   繁体   English

角度ng服务命令

[英]Angular ng serve command

I just make a migration from angular 5 to angular 7. After that i can't run the project. 我只是从5号角向7号角迁移。此后,我无法运行该项目。 When I type ng serve I get this error: 当我输入ng serve时,出现以下错误:

The serve command requires to be run in an Angular project, but a project definition could not be found. serve命令需要在Angular项目中运行,但是找不到项目定义。

Here is my package.json : 这是我的package.json

dependencies": {
"@angular/animations": "7.1.3",
"@angular/common": "7.1.3",
"@angular/compiler": "7.1.3",
"@angular/core": "7.1.3",
"@angular/forms": "7.1.3",
"@angular/http": "7.1.3",
"@angular/platform-browser": "7.1.3",
"@angular/platform-browser-dynamic": "7.1.3",
"@angular/router": "7.1.3",
"@ng-idle/core": "^2.0.0-beta.15",
"@ng-idle/keepalive": "^2.0.0-beta.15",
"@ngrx/store": "^5.2.0",
"angular2-chartjs": "^0.5.1",
"angular2-draggable": "^1.4.2",
"angular2-moment": "^1.9.0",
"bootstrap": "^4.0.0-beta.2",
"core-js": "^2.4.1",
"datejs": "^1.0.0-rc3",
"file-saver": "^2.0.0-rc.3",
"font-awesome": "^4.7.0",
"install": "^0.12.2",
"jquery": "^3.3.1",
"jspdf": "^1.4.1",
"ngx-cookie-service": "^1.0.10",
"ngx-treeview": "^6.0.1",
"popper.js": "^1.14.3",
"rxjs": "^6.3.3",
"zone.js": "^0.8.26"
},   
"devDependencies": {
"@angular/cli": "7.1.3",
"@angular/compiler-cli": "7.1.3",
"@angular/language-service": "7.1.3",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/jspdf": "^1.1.31",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "^5.4.1",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "3.1.6"
}

Does someone have an idea? 有人有主意吗?

Thanks in advance 提前致谢

when upgrading from 5 to 7, angular changed it's cli configuration format. 从5升级到7后,angular更改了cli配置格式。

angular-cli.json -> angular.json angular-cli.json > angular.json

But doing the update the manual way isn't the preferred way. 但是手动更新不是首选方法。

The best way is to use the cli to do the updating for you. 最好的方法是使用cli为您进行更新。 This web page will help you: 该网页将帮助您:

https://update.angular.io/ https://update.angular.io/

But basically you install angular cli globally 但基本上,您是在全球范围内安装angular cli

npm i -g @angular/cli

then run 然后跑

ng update @angular/cli
ng update @angular/core

As mentioned above please use https://update.angular.io/ update guides to update your app. 如上所述,请使用https://update.angular.io/更新指南来更新您的应用程序。

I would like to add something to the answer. 我想在答案中添加一些内容。 The error occurs because of an incorrect update, There won't be an angular.json file in your project. 由于不正确的更新而发生错误,您的项目中不会有angular.json文件。 I have noticed that even after running ng update @angular/cli command and following all the steps at https://update.angular.io/ this issue occurs, 我注意到,即使在执行ng update @ angular / cli命令并按照https://update.angular.io/的所有步骤进行操作之后,也会出现此问题,

During installation(update) Check in the terminal, whether the installation was successful or not if there is any error fix them. 在安装(更新)过程中,请在终端中检查安装是否成功,如果有任何错误,请修复它们。

remove package-lock.json & node_modules, npm cache verify, update global angular cli as well reinstall angular/cli, update cli 删除package-lock.json和node_modules,验证npm缓存,更新全局angular cli并重新安装angular / cli,更新cli

Update the angular 5 to angular 7 please follows the below steps:- 将角度5更新为角度7,请按照以下步骤操作:-

  1. Make sure NodeJS version is 8.9+ if not update it. 如果未更新,请确保NodeJS版本为8.9+。

     sudo npm install n -g sudo n stable sudo n latest 
  2. Update Angular cli globally and locally, and migrate the old configuration .angular-cli.json to the new angular.json format by running the following: 全局和本地更新Angular cli,并通过运行以下命令将旧配置.angular-cli.json迁移为新的angular.json格式:

    npm install -g @angular/cli npm install -g @ angular / cli
    npm install @angular/cli npm安装@ angular / cli
    ng update @angular/cli ng update @ angular / cli

  3. Update all of your Angular framework packages to v7,and the correct version of RxJS and TypeScript by running the following: 通过运行以下命令,将所有Angular框架软件包更新到v7,以及正确版本的RxJS和TypeScript:

    ng update @angular/core ng更新@ angular / core

  4. Update Angular Material to the latest version by running the following: 通过运行以下命令将Angular Material更新到最新版本:

    ng update @angular/material ng更新@ angular / material

  5. There are no breaking changes in Angular itself but they are in RxJS, so don't forget to use rxjs-compat library to work with legacy code. Angular本身并没有重大变化,但它们在RxJS中,因此不要忘记使用rxjs-compat库来处理遗留代码。

    npm install --save rxjs-compat npm install-保存rxjs-compat

After update all packages, so remove the package.lock.json and node_module. 更新所有软件包后,请删除package.lock.json和node_module。 And run the these command:- 并运行以下命令:

npm install

Hope its work for you. 希望它为您工作。 Refer https://update.angular.io/ for more detailed guide. 请参阅https://update.angular.io/了解更多详细指南。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM