首页 > 解决方案 > 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
    }
  }
}

标签: angularjsangular

解决方案


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


推荐阅读