【问题标题】:TypeError: Cannot read properties of undefined (reading 'match')TypeError:无法读取未定义的属性(读取“匹配”)
【发布时间】:2022-01-01 02:10:27
【问题描述】:

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

【问题讨论】:

  • 在移除 package-lock 并使用 npm install 重新安装所有模块后,您是否完全移除了 node_modules? “手动删除 node_modules 中的 bin 文件夹”是什么意思?您应该删除整个 node_modules,而不是其中的任何内容。
  • @AliDemirci,我更新了问题,我也删除了 node_modules 文件夹并调用了 npm install。但这没有帮助。
  • 你确定你也在 package.json 上更新了 angular 的包版本吗?
  • 我注意到我没有升级@angular/cdk 和@angular/material。我修复了它,重新安装了依赖项,但仍然遇到同样的问题。

标签: angular npm angular12 angular13


【解决方案1】:

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

我已将tsconfig.json 中的commonjs 更改为es2020,并添加了"moduleResolution": "node"

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2022-01-05
      • 1970-01-01
      • 2022-07-06
      • 2022-07-12
      • 2022-01-15
      • 1970-01-01
      • 2021-04-04
      • 1970-01-01
      • 2021-11-26
      相关资源
      最近更新 更多