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

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

我已将我的 Angular 应用程序从 12 版本升级到 13 版本。我在单元测试 运行.

期间开始收到此错误
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')

我试过这个解决方案,但没有用。

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

您有解决方法吗?是否与Angular版本升级有关?

我在这个答案中找到了解决方案

我在tsconfig.json中将commonjs更改为es2020并且还添加了"moduleResolution": "node"

对我来说,我使用的是 config.env,但忘记在连接 url 前加上“ATLAS_URI=”。添加“ATLAS_URI=”到我的 config.env 修复了我的 TypeError。

我已通过在 tsconfig.json "target": "es2020" 中设置来解决问题, tsconfig.app.json "模块": "es2020", tsconfig.spec.json "模块": "es2020".