You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行ng add @nguniversal/express-engine时提示Schema不合法

问题:添加Angular Universal时Schema验证失败

问题场景

执行以下命令将Angular项目改造为Angular Universal时触发Schema不合法错误:

ng add @nguniversal/express-engine --clientProject cookbook

控制台错误信息

gettingstarted@gettingstarted:~/WebstormProjects/cookbook$ ng add @nguniversal/express-engine --clientProject cookbook
ℹ Using package manager: npm
✔ Found compatible package version: @nguniversal/express-engine@14.2.0.
✔ Package information loaded.

The package @nguniversal/express-engine@14.2.0 will be installed and executed.
Would you like to proceed? Yes
✔ Packages successfully installed.
Schematic input does not validate against the Schema: {"clientProject":"cookbook","project":"cookbook"}
Errors:

Data path "" must NOT have additional properties(clientProject).
gettingstarted@gettingstarted:~/WebstormProjects/cookbook$

项目angular.json配置

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "cli": {
    "analytics": false
  },
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "cookbook": {
      "projectType": "application",
      "schematics": {
        "@schematics/angular:application": {
          "strict": true
        }
      },
      "root": "",
      "sourceRoot": "src",
      "prefix": "app",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/cookbook",
            "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": [
              "./node_modules/bootstrap/dist/js/bootstrap.min.js",
              "./node_modules/jquery/dist/jquery.js",
              "./node_modules/@popperjs/core/dist/umd/popper.min.js"
            ]
          },
          "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": "cookbook:build:production"
            },
            "development": {
              "browserTarget": "cookbook:build:development"
            }
          },
          "defaultConfiguration": "development"
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "cookbook: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": []
          }
        }
      }
    }
  }
}

解决方案

Angular 14+版本的@nguniversal/express-engine schematic已废弃--clientProject参数,改用--project参数。执行以下命令即可完成安装:

ng add @nguniversal/express-engine --project cookbook

如果项目是单项目结构(angular.json中仅包含一个项目),可直接省略参数,CLI会自动识别默认项目:

ng add @nguniversal/express-engine

内容的提问来源于stack exchange,提问作者GettingStarted

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.16 14:10:36