4

I upgraded my angular cli from the 6 version to the 8.1, Angular universal has changed the simple construction method by @nguniversal/module-map-ngfactory-loader, I should re-deploy, clear the old configuration.

  1. run ng add @nguniversal/express-engine --clientProject [project name]

Error message:

Skipping installation: Package already installed
Target name already exists.
  1. run npm install --save @nguniversal/module-map-ngfactory-loader

  2. build universal, run build:ssr ("npm run build:client-and-server-bundles && npm run compile:server")

Error message: enter image description here

I need to remove some files, modify some files and reinstall @nguniversal/express-engine?

Finn
  • 1,323
  • 5
  • 24
  • 46

1 Answers1

12

To reinstall the angular universal using ng add. You will need to remove all the files was generated by it. Such as

  • src/main.server.ts
  • src/app/app.server.module.ts
  • src/tsconfig.server.json
  • webpack.server.config.js
  • server.ts

In angular.json, you will need to remove the "server" configuration. Something like :

 "server": {
      "builder": "@angular-devkit/build-angular:server",
      "options": {
        "outputPath": "dist/server",
        "main": "src/main.server.ts",
        "tsConfig": "src/tsconfig.server.json"
      },
      "configurations": {
        "production": {
          "fileReplacements": [
            {
              "replace": "src/environments/environment.ts",
              "with": "src/environments/environment.prod.ts"
            }
          ]
        }
      }
    }

After that, you can just do

ng add @nguniversal/express-engine --clientProject [project name]

It should work.

max
  • 613
  • 3
  • 13
  • 26
  • 3
    I tried your method but still got errors: `Skipping installation: Package already installed Cannot read property 'kind' of undefined`. My "server" item does not have "configurations". – Finn Feb 04 '20 at 01:53
  • not working Cannot read property 'some' of undefined – Mohamed Abo Elmagd Jun 28 '20 at 10:01
  • if you getting package already installed, npm uninstall it, then do ng add – P4L Jan 31 '21 at 23:51