angularjs - Angular ng serve 不起作用:serve 命令需要在 Angular 项目中运行,但找不到项目定义
问题描述
当我在我的 Angular 项目中使用 ng serve 时(在正确的位置),它在 cmd 中显示了这个错误。
The serve command requires to be run in an Angular project, but a project definition could not be found.
我也试试这个
Angular Cli 错误:serve 命令需要在 Angular 项目中运行,但找不到项目定义
但这对我也不起作用。我也尝试删除节点模块并重新安装,但不起作用。当我使用 npm start 它工作。为什么?问题是什么?
我的 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>
例如
ng update @angular/cli --migrate-only --from=1.7.3
从这里获取参考https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036
推荐阅读
- java - 如何在不将所有数据混合到一行的情况下将数组保存到字符串中?
- angular - fixture.destroy() 是否应该在 Angular 2+ 单元测试中显式
- python - Bash:/usr/bin/pip:权限被拒绝
- python - 使用 dict.clear() 删除所有值。我怎样才能坚持 dict 值?
- javascript - 即使启用了历史模式,Vue.JS 的路由器也有“#”
- python - 在 python 上保持零小数位
- shell - 使用shell提取行数
- python - 如何将管理菜单限制为管理员、模组和所有者(PyCharm 2020.3.3 Python 3.9.1
- python - Python 线程 ValueError
- python - 当日期之间不包含在数据中时,计算每天的任务数