skip to Main Content

Problem

I have been trying to add seo features for my Angular project by running "ng add @nguniversal/express-engine@next", but keep getting error of

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

I tried to re-install @schematics/angular, but it shows the same error, please advise what could be done to solve this problem.

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

Error logs

[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 version

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

2

Answers


  1. Chosen as BEST ANSWER

    This issue is solved by removing the @nguniversal packages from node_modules and reinstall again.

    Remove @next in the command, because only Angular CLI 12 supports @next (The version using is Angular CLI 9.


  2. ng add @nguniversal/express-engine
    When I run the above command in angular 13. I got the below err.

    Cannot find module 'typescript'
    Require stack:
    node_modules/@nguniversal/express-engine/schematics/install/index.js
    

    I am using angular 15.0.0. I used this command. it worked.

    ng add @nguniversal/express-engine@next
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search