web-dev-qa-db-ja.com

Angular 6 "ワークスペースを使用する前にロードする必要があります。"新しいコンポーネントを生成しようとする場合

angular dotnet newコマンドでasp.netコアプロジェクトを作成すると、angular.jsonファイル(angular 6)がプロジェクトに追加されないため、angularcli。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)
5
MuhanadY

ユーレカ.............

dotnet new angular commanはアプリケーションのルートにangular.jsonファイルを作成しません。一部のサイトでは使用後に

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

コマンドの使用

npm update @angular/cli

これにより、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
            }
          }
        }
      }
    }
  }
}

その後、angular cliコマンドを使用して、コンポーネントとサービスを作成することができました。

幸せになるためのコード

9
MuhanadY

同じエラーが発生しましたが、angular.jsonが問題を引き起こしていました。このエラーは、外部cssパスを手動で追加しているときに発生する可能性があります。 bootstrap cssを参照しているときに、カンマを見逃していました。

スタイル配列にカスタムCSSを追加しているときに、コンマ(、)を見逃しました

エラーファイル:

以下のコードが表示されている場合は、後にカンマがありません
"../ node_modules/bootstrap/dist /bootstrap.min.css"。

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

        ]

解決策:カンマを追加

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

        ]

CLI error

10

同じエラー。アンインストール、再インストール、アップグレードを試みましたが、ngはまだこのエラー情報を報告しました。

空の〜/ .angular-config.jsonファイルを削除した後、すべてが再び正常に機能しています。

9
Ken Lee

Angle.jsonにいくつかの変更を加えたことを確認します。 angle.jsonファイルに構文上の問題がある場合、このエラーが発生します。これは予期しない動作であり、代わりにファイルに構文の問題があると言うように変更する必要があります。

問題

3

私はangular.jsonファイルを変更しましたが、エラーは見られませんでした。カンマとエンコード(UTF-8)で保存したすべてを再確認した後、ドキュメントをフォーマットし(右クリックしてドキュメントをフォーマット)、10行の冗長行を削除しました。その後、angular cli update、およびコマンドも実行できます。

1
Akabelle

buildOptimizer:trueの後にカンマを追加した後、正常に動作しています。

"configurations": {
        "production": {
          "optimization": true,
          "outputHashing": "all",
          "sourceMap": false,
          "extractCss": true,
          "namedChunks": false,
          "aot": true,
          "extractLicenses": true,
          "vendorChunk": false,
          "buildOptimizer": true //I missed to put comma here...
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ]
        }
      }
1

私は同様のエラーを抱えていました:

「未処理の例外が発生しました:ワークスペース構成ファイルをロードできません:/// Projects /// project/angular.jsonスキーマの検証が失敗し、次のエラーが発生しました:データパス ""に追加のプロパティを含めることはできません(scripts)。 "/ private/var/folder/f8 /を参照してください詳細については、cq9wj86n3gbfj8h64f8jlx2m0000gn/T/ng-5TCBsc/angular-errors.log "を参照してください。"

以前にangular.jsonに追加した余分な 'scripts'キーが原因でした。それを削除し、それは機能しました!

0
QauseenMZ

同じエラーが発生しました。このエラーは次の場合に発生する可能性があります。

  1. @angular/cliバージョンのものである可能性があります。
  2. angular.jsonまたはtsconfig.jsonの行末にあるcomma文字を見逃しました。

  3. angular.jsonまたはtsconfig.jsonファイルのunicodeUTF-8になります)。

  4. angular.jsonまたはtsconfig.jsoncomment行が存在します。 (私の場合、tsconfig.jsonにコメント行がありました)。
{

  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    //"outDir": "./dist/out-tsc", // comment line caused the error. I removed this line
    "outDir": "../content/ManagmentJob",
    "sourceMap": true,
    "declaration": false,
    "module": "es2015",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    ...
}
0
AminRostami