Skip to content

TypeError: Cannot read properties of undefined (reading 'endsWith') #23717

@KristinaB162

Description

@KristinaB162

🐞 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 9

Description

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

  1. Set up a new project with angular cli (no routing, css)
    ng new repro-app
  2. Add in package.json in "devDependencies":
"@angular-builders/custom-webpack":"^14.0.0",
"compression-webpack-plugin":"^10.0.0",
  1. Add a new file in root directory called 'extra-webpack.config.js'
  2. Write this code into 'extra-webpack.config.js':
const CompressionPlugin = require("compression-webpack-plugin");

module.exports = {
    plugins: [
        new CompressionPlugin({
            deleteOriginalAssets: true,
        })
    ],
};
  1. In angular.json change the builder in build to @angular-builders/custom-webpack:browser
  2. Add the option in build:
"customWebpackConfig": {
              "path": "./extra-webpack.config.js"
            },
  1. Run npm i
  2. 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')) {

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions