Angular 6: 找不到本地工作区文件('angular.json')

7

我是一名新手,正在学习Angular 6,我已经从链接下载了现成的Angular模板。

进入根目录并执行npm install后尝试运行应用程序ng serve,但出现了错误。

找不到本地工作区文件('angular.json')。

package.json

{
  "name": "angular-6-registration-login-example",
  "version": "1.0.0",
  "repository": {
    "type": "git",
    "url": "https://github.com/cornflourblue/angular-6-registration-login-example.git"
  },
  "scripts": {
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  },
  "license": "MIT",
  "dependencies": {
    "@angular/common": "^6.0.0",
    "@angular/compiler": "^6.0.0",
    "@angular/core": "^6.0.0",
    "@angular/forms": "^6.0.0",
    "@angular/platform-browser": "^6.0.0",
    "@angular/platform-browser-dynamic": "^6.0.0",
    "@angular/router": "^6.0.0",
    "core-js": "^2.5.5",
    "rxjs": "^6.1.0",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@types/node": "^10.0.4",
    "angular2-template-loader": "^0.6.2",
    "html-webpack-plugin": "^3.2.0",
    "raw-loader": "^0.5.1",
    "ts-loader": "^4.3.0",
    "typescript": "^2.8.3",
    "webpack": "4.8.1",
    "webpack-cli": "^2.1.3",
    "webpack-dev-server": "3.1.4"
  }
}

我的环境配置如下:

Angular CLI: 6.0.3
Node: 8.11.2
OS: linux x64
Angular: 6.0.3
... common, compiler, core, forms, platform-browser
... platform-browser-dynamic, router

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.6.3 (cli-only)
@angular-devkit/core         0.6.3 (cli-only)
@angular-devkit/schematics   0.6.3 (cli-only)
@schematics/angular          0.6.3 (cli-only)
@schematics/update           0.6.3 (cli-only)
rxjs                         6.2.0
typescript                   2.8.4
webpack                      4.8.1

请帮我解决这个问题。


1
执行 npm run start - Vikas
你提供的教程没有使用 Angular CLI。ng serve 是一个 Angular CLI 命令,需要 angular.json 文件才能运行。 - Jun Kang
不客气,伙计。 - Vikas
由于您刚接触Angular,我建议您使用“Angular-CLI”。 - Vikas
4个回答

3

由于您的项目未使用Angular-CLI,因此无法执行ng serve。导致错误的原因是ng serve寻找此配置文件来启动您的应用程序。

找不到本地工作区文件('angular.json')。

它使用webpack和所有webpack配置都存储在webpack.config.js中。
如果您查看package.json下的脚本部分,则会看到startbuild

"scripts": {
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  },

您可以使用 npm 来执行这些脚本。
执行 npm run start 来进行开发构建。


0
当我收到这个错误信息时,我运行了“npm install”,我的项目获取了所有的模块并成功运行。

0
如果你读取package.json文件,会发现没有安装angular/cli,因此运行ng serve不起作用。 package.json文件显示了以下命令,你应该运行npm start:
  "scripts": {
    "build": "webpack --mode production",
    "start": "webpack-dev-server --mode development --open"
  }

-1

我一直在使用最新版本的Angular 6,但现在需要处理一个版本为1.6.8的项目。我无法运行ng serve,因为出现了找不到angular.json的错误。

这是package.json文件:

{
  "name": "mktools2.0",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.0.0-beta.2",
    "@angular/animations": "^5.2.0",
    "@angular/common": "^5.2.0",
    "@angular/compiler": "^5.2.0",
    "@angular/core": "^5.2.0",
    "@angular/forms": "^5.2.0",
    "@angular/http": "^5.2.0",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@ng-bootstrap/ng-bootstrap": "^1.0.2",
    "@ngu/carousel": "^1.4.8",
    "bootstrap": "^4.0.0-beta.2",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular/cli": "1.6.8",
    "@angular/compiler-cli": "^5.2.0",
    "@angular/language-service": "^5.2.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@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.1.2",
    "ts-node": "~4.1.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接