Angular Universal安装报错:Schematic输入不匹配Schema如何解决?
问题:Angular Universal安装报错处理
我尝试给名为Authentication的Angular项目安装Angular Universal,执行的命令如下:
ng add @nguniversal/express-engine --clientProject Authentication
项目在angular.json中的配置如下:
angular.json配置
{ "$schema": "./node_modules/@angular/cli/lib/config/schema.json", "version": 1, "newProjectRoot": "projects", "projects": { "Authentication": { "projectType": "application", "schematics": {}, "root": "", "sourceRoot": "src", "prefix": "app", "architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/authentication", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.app.json", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "src/styles.css" ], "scripts": [ ] }, "configurations": { "production": { "budgets": [ { "type": "initial", "maximumWarning": "500kb", "maximumError": "1mb" }, { "type": "anyComponentStyle", "maximumWarning": "2kb", "maximumError": "4kb" } ], "fileReplacements": [ { "replace": "src/environments/environment.ts", "with": "src/environments/environment.prod.ts" } ], "outputHashing": "all" }, "development": { "buildOptimizer": false, "optimization": false, "vendorChunk": true, "extractLicenses": false, "sourceMap": true, "namedChunks": true } }, "defaultConfiguration": "production" }, "serve": { "builder": "@angular-devkit/build-angular:dev-server", "configurations": { "production": { "browserTarget": "Authentication:build:production" }, "development": { "browserTarget": "Authentication:build:development" } }, "defaultConfiguration": "development" }, "extract-i18n": { "builder": "@angular-devkit/build-angular:extract-i18n", "options": { "browserTarget": "Authentication:build" } }, "test": { "builder": "@angular-devkit/build-angular:karma", "options": { "main": "src/test.ts", "polyfills": "src/polyfills.ts", "tsConfig": "tsconfig.spec.json", "karmaConfig": "karma.conf.js", "assets": [ "src/favicon.ico", "src/assets" ], "styles": [ "src/styles.css" ], "scripts": [] } } } } } }
包已成功安装,package.json内容如下:
package.json内容
{ "name": "authentication", "version": "0.0.0", "scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", "test": "ng test" }, "private": true, "dependencies": { "@angular/animations": "^14.0.0", "@angular/common": "^14.0.0", "@angular/compiler": "^14.0.0", "@angular/core": "^14.0.0", "@angular/forms": "^14.0.0", "@angular/localize": "^14.0.0", "@angular/platform-browser": "^14.0.0", "@angular/platform-browser-dynamic": "^14.0.0", "@angular/router": "^14.0.0", "@ng-bootstrap/ng-bootstrap": "^13.0.0", "@ngrx/effects": "^14.3.0", "@ngrx/router-store": "^14.3.0", "@ngrx/store": "^14.3.0", "@nguniversal/express-engine": "^14.1.0", "@popperjs/core": "^2.10.2", "bootstrap": "^5.2.0", "rxjs": "~7.5.0", "tslib": "^2.3.0", "zone.js": "~0.11.4" }, "devDependencies": { "@angular-devkit/build-angular": "^14.2.1", "@angular/cli": "~14.2.1", "@angular/compiler-cli": "^14.0.0", "@ngrx/store-devtools": "^14.3.0", "@types/jasmine": "~4.0.0", "jasmine-core": "~4.3.0", "karma": "~6.4.0", "karma-chrome-launcher": "~3.1.0", "karma-coverage": "~2.2.0", "karma-jasmine": "~5.1.0", "karma-jasmine-html-reporter": "~2.0.0", "typescript": "~4.7.2" } }
但执行命令后仍收到以下错误:
报错信息
PS C:\Users\Administrator\OneDrive\Documents\Learn-Angular\Angular-Video-Tutorial\Authentication> ng add @nguniversal/express-engine --clientProject Authentication ℹ Using package manager: npm ✔ Found compatible package version: @nguniversal/express-engine@14.1.0. ✔ Package information loaded. The package @nguniversal/express-engine@14.1.0 will be installed and executed. Would you like to proceed? Yes ✔ Packages successfully installed. Schematic input does not validate against the Schema: {"clientProject":"Authentication","project":"Authentication"} Errors: Data path "" must NOT have additional properties(clientProject). PS C:\Users\Administrator\OneDrive\Documents\Learn-Angular\Angular-Video-Tutorial\Authentication>
问题原因与解决方法
这个报错是因为Angular 14版本的@nguniversal/express-engine已弃用--clientProject参数,改用--project指定项目名。你执行的命令中同时传递了--clientProject和自动识别的--project参数,导致Schema校验失败。
解决步骤:
- 先卸载已安装的包:
npm uninstall @nguniversal/express-engine
- 使用正确的参数重新安装:
ng add @nguniversal/express-engine --project Authentication
如果你的项目是唯一的默认项目,也可以直接执行:
ng add @nguniversal/express-engine
验证安装结果:
安装完成后,检查angular.json是否新增了server、serve-ssr等architect配置,同时package.json会添加SSR相关脚本,比如serve:ssr、build:ssr等。
内容的提问来源于stack exchange,提问作者vijay s
相关产品推荐
相关产品推荐

