-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Description
🐞 Bug report
Command (mark with an x)
- new
- build
- serve
- test
- e2e
- generate
- add
- update
- lint
- extract-i18n
- run
- config
- help
- version
- doc
Is this a regression?
Yes, the previous version in which this bug was not present was: Angular Version 9Description
After updating Angular from version 9 to 14, the build no longer works because a property is now undefined. I use the "@angular-builders/custom-webpack" with the Webpack CompressionPlugin, because i want my build files being compressed. To not have the compressed and uncompressed files in the dist directory, the 'deleteOriginalAssets' property is set to true. But the @angular-devkit/build-angular module wants to calculate the statistics and needs the deleted files. In version 9 it just returns 0 for the sizes. Now the build process breaks because in line 175 in the file @angular-devkit/build-angular/src/webpack/plugins/analytics.js the property firstFile is undefined.
🔬 Minimal Reproduction
- Set up a new project with angular cli (no routing, css)
ng new repro-app - Add in package.json in "devDependencies":
"@angular-builders/custom-webpack":"^14.0.0",
"compression-webpack-plugin":"^10.0.0",
- Add a new file in root directory called 'extra-webpack.config.js'
- Write this code into 'extra-webpack.config.js':
const CompressionPlugin = require("compression-webpack-plugin");
module.exports = {
plugins: [
new CompressionPlugin({
deleteOriginalAssets: true,
})
],
};
- In angular.json change the builder in build to
@angular-builders/custom-webpack:browser - Add the option in build:
"customWebpackConfig": {
"path": "./extra-webpack.config.js"
},
- Run
npm i - Try to run
npm run build-> you will see an error
🔥 Exception or Error
An unhandled exception occurred: Cannot read properties of undefined (reading 'endsWith')
Anything else relevant?
For a quick fix i just changed the line 175 in node_modules/@angular-devkit/build-angular/src/webpack/plugins/analytics.js from this:
if (firstFile.endsWith('.css')) {
to this:
if (firstFile && firstFile.endsWith('.css')) {