Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 of 15 tasks
KristinaB162 opened this issue Aug 10, 2022 · 1 comment · Fixed by #23719
Closed
1 of 15 tasks

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

KristinaB162 opened this issue Aug 10, 2022 · 1 comment · Fixed by #23719
Labels

Comments

@KristinaB162
Copy link

KristinaB162 commented Aug 10, 2022

🐞 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')) {

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Aug 10, 2022
…ith no files

This commit updates to bundle stats logic to skip checking chunks with no files.

Closes angular#23717
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Aug 10, 2022
…ith no files

This commit updates to bundle stats logic to skip checking chunks with no files.

Closes angular#23717
clydin pushed a commit that referenced this issue Aug 10, 2022
…ith no files

This commit updates to bundle stats logic to skip checking chunks with no files.

Closes #23717

(cherry picked from commit 7de9b47)
clydin pushed a commit that referenced this issue Aug 10, 2022
…ith no files

This commit updates to bundle stats logic to skip checking chunks with no files.

Closes #23717
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
2 participants