Angular 6"工作区需要在使用前加载." 在尝试生成新组件时

Muh*_*adY 5 asp.net-core angular angular6

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

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)
Run Code Online (Sandbox Code Playgroud)

Ash*_*wat 10

我得到了同样的错误,是的angular.json正在解决问题.手动添加外部css路径时可能会发生此错误.我在引用bootstrap css时错过了逗号.

在样式数组中添加自定义CSS时,我错过了逗号(,)

错误文件:

如果您在
"../node_modules/bootstrap/dist/bootstrap.min.css" 之后看到以下代码,则缺少逗号.

"styles": [
          "../node_modules/bootstrap/dist/bootstrap.min.css"
          "src/styles.css"

        ]
Run Code Online (Sandbox Code Playgroud)

解决方案: Comma补充道

"styles": [
          "../node_modules/bootstrap/dist/bootstrap.min.css",
          "src/styles.css"

        ]
Run Code Online (Sandbox Code Playgroud)

CLI错误


Muh*_*adY 9

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

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

npm install --save--dev @angular/cli@latest
Run Code Online (Sandbox Code Playgroud)

命令使用

npm update @angular/cli
Run Code Online (Sandbox Code Playgroud)

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

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

 {
  "$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
            }
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

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

代码要快乐


Ken*_*Lee 9

同样的错误。尝试卸载,重新安装和升级,仍然会报告此错误信息。

删除一个空的〜/ .angular-config.json文件后,一切恢复正常。