简体   繁体   English

Angular ng serve 不起作用:Serve 命令需要在 Angular 项目中运行,但找不到项目定义

[英]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.

相关问题 “serve 命令需要在 Angular 项目中运行,但找不到项目定义。” - “The serve command requires to be run in an Angular project, but a project definition could not be found.” 没有项目支持“服务”目标。 卡住并且无法在我的本地主机上运行 Angular 项目 - No projects support the 'serve' target. Stuck and can't run Angular project on my localhost 约曼角项目在咕gr声与咕unt声发球上看起来有所不同 - Yeoman angular project looks different in grunt vs grunt serve 在角度2应用程序中运行时出现错误 - ng serve error while running in angular 2 application 从Java项目中调用“ grunt serve”命令 - Call the “grunt serve” command from java project ng serve在Windows10上不起作用(angular-cli,节点6.3.0) - ng serve doesn't work on Windows10 (angular-cli, node 6.3.0) 使用ionic serve --lab命令运行项目时,$ state.go无法正常工作 - $state.go is not working when project is run with ionic serve --lab command 使用NginX服务Angular应用程序 - Serve Angular Application With NginX 如何通过子目录提供 Angular 2 CLI ng - How To have Angular 2 CLI ng serve via subdirectory 当grunt发送时,找不到Angular.js模块:dist,但是grunt服务正常 - Angular.js Module not found when grunt serve:dist, but grunt serve works fine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM