網站搜尋

angular - 錯誤:模式驗證失敗,存在以下錯誤:資料路徑 "" 不應該有額外的屬性(project)


將應用程式從 Angular 5 遷移到 6 後,執行 ng serve 時出現以下錯誤。

Schema validation failed with the following errors:
    Data path "" should NOT have additional properties(project).
  Error: Schema validation failed with the following errors:
    Data path "" should NOT have additional properties(project).
      at MergeMapSubscriber._registry.compile.pipe.operators_1.concatMap.validatorResult [as project] (.../TemplateApp/me-cmf-web-template-angular/node_modules/@angular-devkit/core/src/workspace/workspace.js:210:42)
      at MergeMapSubscriber._tryNext (/.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/operators/mergeMap.js:65:27)
      at MergeMapSubscriber._next (.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/operators/mergeMap.js:55:18)
      at MergeMapSubscriber.Subscriber.next (/home/training/Attinad_Projects/TemplateApp/me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/Subscriber.js:64:18)
      at MergeMapSubscriber.notifyNext (.../TemplateApp/me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/operators/mergeMap.js:84:26)
      at InnerSubscriber._next (.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/InnerSubscriber.js:25:21)
      at InnerSubscriber.Subscriber.next (/.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/Subscriber.js:64:18)
      at MapSubscriber._next (.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/operators/map.js:52:26)
      at MapSubscriber.Subscriber.next (/.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/Subscriber.js:64:18)
      at SwitchMapSubscriber.notifyNext (.../me-cmf-web-template-angular/node_modules/@angular-devkit/core/node_modules/rxjs/internal/operators/switchMap.js:77:26)

我認為錯誤出在 .angular.json 文件上,我是從 .angular-cli.json 重新命名的。

我的 .angular.json 文件如下:

{
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "project": {
        "name": "mediaweb"
    },
    "apps": [{
            "root": "src",
            "outDir": "dist/browser",
            "assets": [
                "assets",
                "favicon.ico"
            ],
            "index": "index.html",
            "main": "main.ts",
            "polyfills": "polyfills.ts",
            "test": "test.ts",
            "tsconfig": "tsconfig.app.json",
            "testTsconfig": "tsconfig.spec.json",
            "prefix": "app",
            "styles": [
                "styles.scss",
                "../node_modules/owl.carousel/dist/assets/owl.carousel.css",
                "../node_modules/owl.carousel/dist/assets/owl.theme.default.css",
                "../node_modules/video.js/dist/video-js.css"
            ],
            "scripts": [
                "../node_modules/jquery/dist/jquery.js",
                "../node_modules/owl.carousel/dist/owl.carousel.js",
                "../node_modules/video.js/dist/ie8/videojs-ie8.js",
                "../node_modules/video.js/dist/video.js"
            ],
            "environmentSource": "environments/environment.ts",
            "environments": {
                "dev": "environments/environment.dev.ts",
                "prod": "environments/environment.prod.ts"
            }
        },
        {
            "platform": "server",
            "root": "src",
            "outDir": "dist/server",
            "assets": [
                "assets",
                "favicon.ico"
            ],
            "index": "index.html",
            "main": "main.server.ts",
            "test": "test.ts",
            "tsconfig": "tsconfig.server.json",
            "testTsconfig": "tsconfig.spec.json",
            "prefix": "app",
            "styles": [
                "styles.scss"
            ],
            "scripts": [],
            "environmentSource": "environments/environment.ts",
            "environments": {
                "dev": "environments/environment.dev.ts",
                "prod": "environments/environment.prod.ts"
            }
        }
    ],
    "e2e": {
        "protractor": {
            "config": "./protractor.conf.js"
        }
    },
    "lint": [{
            "project": "src/tsconfig.app.json",
            "exclude": ["**/node_modules/**", "**/UI/**"]
        },
        {
            "project": "src/tsconfig.spec.json",
            "exclude": "**/node_modules/**"
        },
        {
            "project": "e2e/tsconfig.e2e.json",
            "exclude": "**/node_modules/**"
        }
    ],
    "test": {
        "karma": {
            "config": "./karma.conf.js"
        }
    },
    "defaults": {
        "styleExt": "scss",
        "component": {}
    }
}

我應該重新結構化這個 json 文件嗎?如果是,該怎麼做?

任何幫助都很好。

答案#1

此問題通常是因為您的 package.json 文件中的版本不匹配所造成的。

在我的 Angular 7 應用程式中,我已將 "@angular-devkit/build-angular": "^0.800.2" 改為 "@angular-devkit/build-angular": "~0.7.0"。

然後我在刪除 node_modules 後執行了命令 npm install。

旁注:請小心使用 ^。如果所使用的套件有重大變更,你現在能運作的程式碼將來可能無法運作。

使用相同的 package-lock.json 檔案也會有神奇的效果。

答案#2

我的應用程式是使用 Angular 7.2.3

從 angular.json 中移除 "es5BrowserSupport": true。現在 npm start 可以運行了。

答案#3

只需打開 angular.json 文件並刪除

"extractCss": true

在…上

生產部門。

答案#4

當我遇到版本錯誤問題時,以下命令對我有效:

第一次運行:

npm update

第二次運行:

ng update

第三次運行:(它將更新所有不匹配的套件)

npm update --all --force

答案#5

首先:

npm uninstall @angular-devkit/build-angular

下一個:

npm install @angular-devkit/[email 

答案#6

從 Angular 9 升級到 10 非常容易(所有額外的詳細資訊在這裡:https://update.angular.io/?v=9.0-10.0) :

確保你的封裝檔案已在版本控制中,並且所有變更都已提交。這將會覆蓋你的封裝檔案。最好你在新的實驗分支中嘗試。

npm install -g npm-check-updates
ncu -u
ng update --all --force

在新的架構中,不再允許使用鍵 es5BrowserSupport;請在您的 angular.json 中刪除以下行:

"es5BrowserSupport": true

然後只需重新啟動你的應用程式:

npm start