[英]Angular ng serve not work:The serve command requires to be run in an Angular project, but a project definition could not be found
When I used ng serve in my Angular project (in to correct place) its show this error in cmd.当我在我的 Angular 项目中使用 ng serve 时(在正确的位置),它在 cmd 中显示此错误。
The serve command requires to be run in an Angular project, but a project definition could not be found.
I try this also我也试试这个
Angular Cli Error: The serve command requires to be run in an Angular project, but a project definition could not be found Angular Cli 错误:服务命令需要在 Angular 项目中运行,但找不到项目定义
but this also not work for me.但这对我也不起作用。 I tried also to delete node-module and reinstall, but not work.
我也尝试删除节点模块并重新安装,但不起作用。 When I used npm start it work.
当我使用 npm start 时它可以工作。 Why?
为什么? What is the problem?
问题是什么?
My angular-cli.json code here我的 angular-cli.json 代码在这里
"project": {
"version": "1.0.0-beta.28.3",
"name": "angular-src"
},
"apps": [
{
"root": "src",
"outDir": "../public",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"styles": [
"styles.css"
],
"scripts": [],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"files": "src/**/*.ts",
"project": "src/tsconfig.json"
},
{
"files": "e2e/**/*.ts",
"project": "e2e/tsconfig.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
ng update @angular/cli --migrate-only --from=<WhateverVersionYouAreCurrentlyOn>
eg例如
ng update @angular/cli --migrate-only --from=1.7.3
getting ref from here https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036从这里获取参考https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036
Make sure that you are in the project directory in the terminal before running "ng serve".
在运行“ng serve”之前,请确保您位于终端中的项目目录中。
Let's say your folder structure is as follows:假设您的文件夹结构如下:
|-Documents
|---my_projects
|-----angular_project
Make sure that your terminal is in "angular_project" for example.例如,确保您的终端在“angular_project”中。 ie
IE
username@PC_NAME:~/Documents/my_projects/angular_project$ ng serve
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.