Fix the TerserPlugin Storybook build error in Angular

Published June 24, 2021

I was attempting to install Storybook on an Angular 9 application and kept getting the following error when running the build-storybook command-line utility: 92% chunk asset optimization TerserPlugin previousExtractedCommentsSource.replace is not a function.

I tried upgrading the Angular application from Angular 9 to Angular 11 but I noticed that the build-storybook error was still occuring on Angular 11.

When I had first used npx sb init to install Storybook, I got the following version installed in the package.json file of my Angular application. I was not able to get build-storybook to work with this version.

"@storybook/angular": "^6.2.9",

I then decided to try upgrading my Storybook installation with the latest pre-release version of Storybook by using npx sb upgrade --prerelease. This gave me the following version.

"@storybook/angular": "^6.3.0-beta.14",

I'm now able to run build-storybook from the command-line of the Angular 9 app successfully with this prerelease version of Storybook. I hope this can help anyone else struggling with the same error.