Ionic 5 --prod build error

I created a new Ionic 5 project. It doesn’t have a lot in it.
It works fine in development but when I run “ionic build --prod” or “ionic build --prod --release”
I get the following error:

ERROR in ./node_modules/@ionic/angular/fesm2015/ionic-angular.js
Module build failed (from ./node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js):
TypeError: Cannot read property 'kind' of undefined
    at isAngularDecoratorMetadataExpression (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:265:35)    at checkNodeForDecorators (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:77:21)
    at visitNodes (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16514:30)
    at Object.forEachChild (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16740:24)
    at checkNodeForDecorators (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16505:24)
    at Object.forEachChild (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16635:21)
    at checkNodeForDecorators (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16505:24)
    at Object.forEachChild (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16703:24)
    at checkNodeForDecorators (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16505:24)
    at Object.forEachChild (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16692:24)
    at checkNodeForDecorators (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\@angular-devkit\build-optimizer\src\transforms\scrub-file.js:68:31)
    at visitNode (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16505:24)
    at Object.forEachChild (R:\WekaDevelopment\Client Prototypes\Blueprint\node_modules\typescript\lib\typescript.js:16599:21)
[ERROR] An error occurred while running subprocess ng.

$ ionic info

Ionic:

Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.0.4
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.1.2

Utility:

cordova-res : 0.9.0
native-run : not installed

System:

NodeJS : v10.17.0 (C:\Program Files\nodejs\node.exe)
npm : 6.11.3
OS : Windows 10

This resolved the problem for me:

Also see: