angular - 类型错误 : Cannot read properties of undefined (reading 'match' )

标签 angular npm angular12 angular13

我已将我的 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版本升级有关?

最佳答案

我在这个答案中找到了解决方案 https://stackoverflow.com/a/68797111/3387259

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

关于angular - 类型错误 : Cannot read properties of undefined (reading 'match' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70066396/

相关文章:

angular - 如何在Angular组件中模拟服务功能以进行单元测试

css - 缩小并添加哈希到 css 文件 webpack

php - 如何将 node_modules 文件夹部署到生产服务器?

Angular - 选择下拉列表为空

bootstrap-5 - Bootstrap 5悬停悬停焦点悬停焦点事件不起作用

java - 将日期从 Angular 日期选择器传递到java后端的理想方法?

angular - ionic 服务需要错误@ionic/app-scripts才能正常工作

node.js - npm 错误!缺少脚本 : deploy

node.js - Electron 和 Electron 预建有什么区别?

Angular 库 - 无法读取未定义的属性 'ɵmod'