'TypeError: Cannot read properties of undefined (reading 'match')

I have upgraded my Angular application from 12 to 13 version. And I started getting this error during unit test run.

Chrome Headless 94.0.4606.61 (Windows 10) AppComponent should create the app FAILED
        TypeError: Cannot read properties of undefined (reading 'match')
            at extractCommentsWithHash (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:9130:18)
            at ShadowCss.shimCssText (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:8694:34)
            at map (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:22402:26)
            at Array.map (<anonymous>)
            at compileStyles (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:22401:19)
            at compileComponentFromMetadata (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:21948:13)
            at CompilerFacadeImpl.compileComponentFromMeta (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:22570:21)
            at CompilerFacadeImpl.compileComponent (http:###/_karma_webpack_/webpack:/node_modules/@angular/compiler/fesm2020/compiler.mjs:22560:21)
            at Function.get (http:###/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:24583:47)
            at getComponentDef (http:###/_karma_webpack_/webpack:/node_modules/@angular/core/fesm2020/core.mjs:1119:16)
        Failed: Cannot read properties of undefined (reading 'match')

I tried this solution but it didn't work.

manually remove package-lock.json
manually remove folder node_modules
npm install

Do you have any ideas how to fix it? Is it connected to Angular version upgrade?



Solution 1:[1]

I found the solution in this answer https://stackoverflow.com/a/68797111/3387259

I have changed commonjs to es2020 in tsconfig.json and also added "moduleResolution": "node".

Solution 2:[2]

For me, I was using a config.env and forgot to put "ATLAS_URI=" before my connection url. Adding "ATLAS_URI=" to my config.env fixed my TypeError.

Solution 3:[3]

I have managed to tsolve the issue by setting in my tsconfig.json "target": "es2020", tsconfig.app.json "module": "es2020", tsconfig.spec.json "module": "es2020".

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 olgacosta
Solution 2 Jwen
Solution 3 AleksandrM