Angular 13,类型错误:_angular_core__WEBPACK_IMPORTED_MODULE_12__。ɵɵstartElement(...) 不是函数
应用程序成功构建并且 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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尽管 package.json 文件中为所有角度库指定的版本应该在整个板上产生相同的版本,但角度/编译器和角度/核心(以及其他关键角度库)之间存在版本不匹配。
尽管包锁定文件中有一些指示符表明所有版本都匹配,但它们并不匹配。
这可以通过运行此命令或类似命令来有针对性地进行验证:
我要感谢 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).
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:
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
我在使用 Angular 16 应用程序时遇到以下错误:
在遵循 Daniel Hokanson 的响应并运行
npm ls @angular/core
后,我注意到我有[电子邮件受保护]
。将该软件包安装到
^16.0.0
清除了该错误。我希望对某人有帮助
I'm on an Angular 16 app and was getting this error:
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