Angular 13,类型错误:_angular_core__WEBPACK_IMPORTED_MODULE_12__。ɵɵstartElement(...) 不是函数

发布于 2025-01-11 14:02:08 字数 2364 浏览 0 评论 0原文

应用程序成功构建并且 ng 服务运行。应用程序将无法成功运行/初始化。

从工作时到发生故障时,没有明显的打字稿代码更改,因此我专注于 html 模板和带有上下文的 tsconfig。

当生成的 main.js 的 html 模板逻辑运行时,在第二个子元素 elementStart 函数执行时,执行在某处/以某种方式失败。

输入图片此处描述

core.mjs:6461 ERROR TypeError: _angular_core__WEBPACK_IMPORTED_MODULE_12__.ɵɵelementStart(...) is not a function
    at AppComponent_Template (app.component.html:2:1)
    at executeTemplate (core.mjs:9593:9)
    at renderView (core.mjs:9396:13)
    at renderComponent$1 (core.mjs:10677:5)
    at renderChildComponents (core.mjs:9261:9)
    at renderView (core.mjs:9421:13)
    at ComponentFactory.create (core.mjs:21574:13)
    at ApplicationRef.bootstrap (core.mjs:26377:42)
    at core.mjs:26060:64
    at Array.forEach (<anonymous>)

app.component.html(d-xxx 元素来自自定义构建角度库,我还构建/管理该库,该库已经过其他消费客户端的测试,并且正在其他项目上工作)

<div>
  <d-layout [staticNavItems]="navItems" [dynamicNavItems]="contextMenuItems" [subMenuButtonLabel]="subMenuLabel"
    subMenuButtonIcon="folder" [loadingMessage]="loadingMessage">
    <div>
      <d-nav-header>
        <div class="d__logo"></div>
        <span class="d__title">
          Some Title
        </span>
      </d-nav-header>
    </div>
    <div>
      <d-content-header class="d__header">
        <d-context-subject></d-context-subject>
        <d-header></d-header>
      </d-content-header>
    </div>
    <div>
      <d-content>
        <router-outlet></router-outlet>
      </d-content>
    </div>
  </d-layout>
</div>

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "module": "esnext",
    "importHelpers": true,
    "target": "es2020",
    "lib": [
      "es2015",
      "es2018",
      "es2020",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

Application successfully builds and ng serve runs. Application will not successfully run/initialize.

There have been no appreciable typescript code changes from when this was working to when failure occurred, so I am focusing on the html template and the tsconfig with context.

The when the html template logic of the generated main.js is run, the execution is failing somewhere/somehow on the second child element elementStart function execution.

enter image description here

core.mjs:6461 ERROR TypeError: _angular_core__WEBPACK_IMPORTED_MODULE_12__.ɵɵelementStart(...) is not a function
    at AppComponent_Template (app.component.html:2:1)
    at executeTemplate (core.mjs:9593:9)
    at renderView (core.mjs:9396:13)
    at renderComponent$1 (core.mjs:10677:5)
    at renderChildComponents (core.mjs:9261:9)
    at renderView (core.mjs:9421:13)
    at ComponentFactory.create (core.mjs:21574:13)
    at ApplicationRef.bootstrap (core.mjs:26377:42)
    at core.mjs:26060:64
    at Array.forEach (<anonymous>)

app.component.html (d-xxx elements come from a custom build angular library I also build/manage that has been tested with other consuming clients and is working on other projects)

<div>
  <d-layout [staticNavItems]="navItems" [dynamicNavItems]="contextMenuItems" [subMenuButtonLabel]="subMenuLabel"
    subMenuButtonIcon="folder" [loadingMessage]="loadingMessage">
    <div>
      <d-nav-header>
        <div class="d__logo"></div>
        <span class="d__title">
          Some Title
        </span>
      </d-nav-header>
    </div>
    <div>
      <d-content-header class="d__header">
        <d-context-subject></d-context-subject>
        <d-header></d-header>
      </d-content-header>
    </div>
    <div>
      <d-content>
        <router-outlet></router-outlet>
      </d-content>
    </div>
  </d-layout>
</div>

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "module": "esnext",
    "importHelpers": true,
    "target": "es2020",
    "lib": [
      "es2015",
      "es2018",
      "es2020",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

┈┾☆殇 2025-01-18 14:02:08

尽管 package.json 文件中为所有角度库指定的版本应该在整个板上产生相同的版本,但角度/编译器和角度/核心(以及其他关键角度库)之间存在版本不匹配。

Angular: 13.1.3    <===================
... animations, common, core, forms, platform-browser

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1302.5
@angular-devkit/build-angular       13.2.5 <================
@angular-devkit/core                13.2.5
@angular-devkit/schematics          13.2.5
@angular/cdk                        13.2.5
@angular/cli                        13.2.5
@angular/compiler                   13.2.5
@angular/compiler-cli               13.2.5
@angular/language-service           13.2.5
@angular/material                   13.2.5
@angular/material-moment-adapter    13.2.5
@angular/platform-browser-dynamic   13.2.5
@angular/router                     13.2.5
@schematics/angular                 13.2.5
ng-packagr                          13.2.1
rxjs                                7.5.4
typescript                          4.5.5

尽管包锁定文件中有一些指示符表明所有版本都匹配,但它们并不匹配。

这可以通过运行此命令或类似命令来有针对性地进行验证:

npm ls @angular/core

我要感谢 Angular 团队帮助我解决此问题。这是答案和主题的链接。
https://github.com/angular/angular/issues/45265

Even though the versions specified in the package.json file for all of the angular libraries should have resulted in the same version acorsss the board, there was a version mismatch between the angular/compiler and angular/core(and other critical angular libraries).

Angular: 13.1.3    <===================
... animations, common, core, forms, platform-browser

Package                             Version
-------------------------------------------------------------
@angular-devkit/architect           0.1302.5
@angular-devkit/build-angular       13.2.5 <================
@angular-devkit/core                13.2.5
@angular-devkit/schematics          13.2.5
@angular/cdk                        13.2.5
@angular/cli                        13.2.5
@angular/compiler                   13.2.5
@angular/compiler-cli               13.2.5
@angular/language-service           13.2.5
@angular/material                   13.2.5
@angular/material-moment-adapter    13.2.5
@angular/platform-browser-dynamic   13.2.5
@angular/router                     13.2.5
@schematics/angular                 13.2.5
ng-packagr                          13.2.1
rxjs                                7.5.4
typescript                          4.5.5

Even though there were some indicators in the package-lock file that all of the versions matched, they did not.

This can be verified in a targeted way by running this or similar commands:

npm ls @angular/core

I'd like to thank the angular team for helping me out with this. Here is a link to the answers and thread.
https://github.com/angular/angular/issues/45265

萌梦深 2025-01-18 14:02:08

我在使用 Angular 16 应用程序时遇到以下错误:

angular_core__WEBPACK_IMPORTED_MODULE_0_.ɵɵtemplate(...) 不是函数

在遵循 Daniel Hokanson 的响应并运行 npm ls @angular/core 后,我注意到我有 [电子邮件受保护]

将该软件包安装到 ^16.0.0 清除了该错误。

我希望对某人有帮助

I'm on an Angular 16 app and was getting this error:

angular_core__WEBPACK_IMPORTED_MODULE_0_.ɵɵtemplate(...) is not a function

After following Daniel Hokanson's response and running npm ls @angular/core, I noticed I had [email protected].

Installing that package to ^16.0.0 cleared that error.

I hope that helps someone

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文