Angular 6“工作区需要在使用前加载."尝试生成新组件时 [英] Angular 6 "Workspace needs to be loaded before it is used." when trying to generate a new Component

查看:17
本文介绍了Angular 6“工作区需要在使用前加载."尝试生成新组件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 angular dotnet new 命令创建 asp.net 核心项目时,不会向项目添加 angular.json 文件(angular 6),因此我们无法使用 angular cli.如果我手动添加 angular.json 文件,项目会在下面给出异常!?

when I create asp.net core project with angular dotnet new command does not add an angular.json file (angular 6) to the project and therefor we are not able to use angular cli. If i add angular.json file manually the project give the exception below!?

Workspace needs to be loaded before it is used. Error: Workspace needs to be loaded before it is used. at Workspace._assertLoaded (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:59:19) at Workspace.getProjectByPath (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:103:14) at Object.getPackageManager (D:\NetAngular\node_modules\@angular\cli\utilities\config.js:97:35) at UpdateCommand.runSchematic (D:\NetAngular\node_modules\@angular\cli\models\schematic-command.js:74:38) at UpdateCommand.<anonymous> (D:\NetAngular\node_modules\@angular\cli\commands\update.js:70:25) at Generator.next (<anonymous>) at D:\NetAngular\node_modules\@angular\cli\commands\update.js:7:71 at new Promise (<anonymous>) at __awaiter (D:\NetAngular\node_modules\@angular\cli\commands\update.js:3:12) at UpdateCommand.run (D:\NetAngular\node_modules\@angular\cli\commands\update.js:69:16)

推荐答案

EUREKA................

EUREKA.............

dotnet new angular comman 不会在应用程序的根目录上创建 angular.json 文件.在某些网站上,他们说使用

dotnet new angular comman does not create an angular.json file on the root of the application. in some sites they say that after using

npm install --save--dev @angular/cli@latest

命令使用

npm update @angular/cli

这会将您的 angular-cli.json 文件迁移到 angular.json 文件!!!但这里的重点是没有 angular-cli.json 文件,也没有 angular.json.

which will migrate you angular-cli.json file to angular.json file!!! but the point here there is no angular-cli.json file nor angular.json.

我通过创建我自己的 angular.json 文件解决了这个问题(你可以用你的项目名称更改 vega)

I solved the problem by creating my own angular.json file as bellow (you may change vega with your project name)

 {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "vega": {
      "root": "",
      "sourceRoot": "ClientApp",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "ClientApp/dist/vega"
          },
          "configurations": {
            "production": {
              "fileReplacements": [{
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
              }],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        }
      }
    }
  }
}

在那之后,我能够使用 angular cli 命令并创建组件和服务.

after that i was able to use angular cli command and create components and services.

代码快乐

这篇关于Angular 6“工作区需要在使用前加载."尝试生成新组件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆