ng add @nguniversal/express-engine@next 出错

Error for ng add @nguniversal/express-engine@next

问题

我一直在尝试通过 运行“ng add @nguniversal/express-engine@next”为我的 Angular 项目添加 seo 功能,但不断收到

错误

An unhandled exception occurred: Cannot find module '@schematics/angular/utility/json-file'

我尝试重新安装@schematics/angular,但它显示相同的错误,请告知如何解决此问题。

Error for ng add @nguniversal/express-engine@next

错误日志

[error] Error: Cannot find module '@schematics/angular/utility/json-file'
Require stack:
- /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/common/schematics/add/index.js
- /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/express-engine/schematics/install/index.js
- /Users/ooicw/Documents/roomer-app/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /Users/ooicw/Documents/roomer-app/node_modules/@angular-devkit/schematics/tools/index.js
- /Users/ooicw/Documents/roomer-app/node_modules/@angular/cli/utilities/json-schema.js
- /Users/ooicw/Documents/roomer-app/node_modules/@angular/cli/models/command-runner.js
- /Users/ooicw/Documents/roomer-app/node_modules/@angular/cli/lib/cli/index.js
- /usr/local/lib/node_modules/@angular/cli/lib/init.js
- /usr/local/lib/node_modules/@angular/cli/bin/ng
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
    at Function.Module._load (internal/modules/cjs/loader.js:841:27)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/common/schematics/add/index.js:32:25
    at /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/common/schematics/add/index.js:12:17
    at Object.<anonymous> (/Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/common/schematics/add/index.js:18:3)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Module.require (internal/modules/cjs/loader.js:1025:19)
    at require (internal/modules/cjs/helpers.js:72:18)
    at /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/express-engine/schematics/install/index.js:31:19
    at /Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/express-engine/schematics/install/index.js:12:17
    at Object.<anonymous> (/Users/ooicw/Documents/roomer-app/node_modules/@nguniversal/express-engine/schematics/install/index.js:18:3)

Angular CLI 版本

Angular CLI: 9.1.15
Node: 12.18.3
OS: darwin x64

Angular: 9.1.3
... common, compiler, compiler-cli, core, language-service
... platform-browser, platform-browser-dynamic, router
Ivy Workspace: No

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.7
@angular-devkit/build-angular     0.901.12
@angular-devkit/build-optimizer   0.901.12
@angular-devkit/build-webpack     0.901.12
@angular-devkit/core              9.0.7
@angular-devkit/schematics        9.1.15
@angular/animations               9.1.9
@angular/cdk                      9.2.4
@angular/cli                      9.1.15
@angular/fire                     6.0.0
@angular/flex-layout              9.0.0-beta.29
@angular/forms                    9.1.9
@angular/material                 9.2.4
@angular/platform-server          11.2.3
@angular/service-worker           9.1.11
@ngtools/webpack                  9.1.12
@nguniversal/common               11.1.0-next.0
@nguniversal/express-engine       11.1.0-next.0
@schematics/angular               9.1.15
@schematics/update                0.901.15
rxjs                              6.5.5
typescript                        3.7.5
webpack                           4.43.0

此问题已通过从 node_modules 中删除 @nguniversal 软件包并重新安装来解决。

删除命令中的@next,因为只有Angular CLI 12支持@next(使用的版本是Angular CLI 9.