使用新的构建系统迁移到 Angular 18 后,我收到一个错误:无法读取 null 的属性(读取“bindingStartIndex”)

问题描述 投票:0回答:1

我已将用作应用程序库的项目从 Angular 17 更新为 Angular 18,并且像往常一样更新了所有包。我也接受了迁移到新的构建系统。

npm i [email protected]
ng update @angular/core@18 ng update @angular/cli@18 
ng update @angular-eslint/schematics@18 ng update @angular/material@18

当我运行该库时,我在浏览器控制台中收到此错误:

main.ts:10 ERROR TypeError: Cannot read properties of null (reading 'bindingStartIndex')
    at ɵɵelementStart (core.mjs:23501:53)
    at AppComponent2_Template (template.html:1:1)
    at executeTemplate (core.mjs:11788:5)
    at renderView (core.mjs:12950:7)
    at renderComponent (core.mjs:12896:3)
    at renderChildComponents (core.mjs:12996:5)
    at renderView (core.mjs:12978:7)
    at ComponentFactory.create (core.mjs:16260:9)
    at _ApplicationRef.bootstrap (core.mjs:31811:38)
    at core.mjs:33216:56

在我的

package.json
中,我在本地添加了一个包,它是应该渲染的组件,我不知道这是否可能是问题所在,并且某些东西改变了本地导入包的方式。

"@mylib/dashboards": "file:./MyLib.Dashboards/dist/dashboards/mylib-dashboards-18.0.0.tgz"

自从在

tsconfig.json
中我已经添加了角度库的路径,这是我看到人们针对这个问题给出的解决方案

“paths": {
  “@angular/*": [
    “node_modules/@angular/*”
  ],

我也尝试在

angular.json
中添加
preserveSymlinks
部分,但没有任何改变。

 "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:application",
          "options": {
             "preserveSymlinks": true,

但是,如果我从“

“@angular/*
”中删除此路径,我不会收到错误,但我测试库的模拟数据不会加载。我使用
InMemoryDataService
创建这个模拟数据,它实现了
InMemoryDbService
创建数据库。

package.json:

{
  "name": "widgets-app",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "jest --coverage --verbose --silent",
    "lint": "ng lint",
    "build_prod": "ng build widgets --configuration production",
    "pack": "cd dist/widgets && npm pack",
    "package": "npm run build_prod && npm run pack",
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^18.2.7",
    "@angular/cdk": "^18.2.7",
    "@angular/common": "^18.2.7",
    "@angular/compiler": "^18.2.7",
    "@angular/core": "^18.2.7",
    "@angular/forms": "^18.2.7",
    "@angular/material": "^18.2.7",
    "@angular/material-moment-adapter": "^18.2.7",
    "@angular/platform-browser": "^18.2.7",
    "@angular/platform-browser-dynamic": "^18.2.7",
    "@angular/router": "^18.2.7",
    "@asymmetrik/ngx-leaflet": "^18.0.1",
    "@mylib/dashboards": "file:../MyLib.Dashboards/dist/dashboards/mylib-dashboards-18.0.0.tgz",
    "@mylib/layout": "^18.0.2",
    "@ngx-translate/core": "^15.0.0",
    "@ngx-translate/http-loader": "^8.0.0",
    "@syncfusion/ej2-angular-pivotview": "^27.1.48",
    "angular-in-memory-web-api": "0.18.0",
    "echarts": "^5.4.3",
    "leaflet": "^1.9.4",
    "leaflet.markercluster": "^1.5.3",
    "moment": "^2.29.4",
    "ng-dynamic-component": "^10.7.0",
    "ngx-daterangepicker-material": "^6.0.4",
    "ngx-echarts": "^18.0.0",
    "ngx-skeleton-loader": "^9.0.0",
    "ngx-translate-multi-http-loader": "^18.1.0",
    "rxjs": "^7.8.1",
    "uuid": "^9.0.0",
    "zone.js": "~0.14.10"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^18.2.7",
    "@angular-eslint/builder": "^18.3.1",
    "@angular-eslint/eslint-plugin": "^18.3.1",
    "@angular-eslint/eslint-plugin-template": "^18.3.1",
    "@angular-eslint/schematics": "^18.3.1",
    "@angular-eslint/template-parser": "^18.3.1",
    "@angular/cli": "^18.2.7",
    "@angular/compiler-cli": "^18.2.7",
    "@ngneat/spectator": "^19.0.0",
    "@types/jest": "^29.5.13",
    "@types/leaflet": "^1.9.12",
    "@typescript-eslint/eslint-plugin": "^8.6.0",
    "@typescript-eslint/parser": "^8.6.0",
    "eslint": "^9.12.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.2.1",
    "jest": "^29.7.0",
    "jest-auto-spies": "^3.0.0",
    "jest-preset-angular": "^14.2.4",
    "jest-sonar": "^0.2.16",
    "ng-mocks": "^14.13.1",
    "ng-packagr": "^18.2.1",
    "prettier": "^3.3.3",
    "typescript": "~5.5.4"
  }
}
angular migration angular18
1个回答
0
投票

您可以尝试从

paths
数组中删除角线,这可能会解决问题。

之前:

“paths": {
  “@angular/*": [
    “node_modules/@angular/*”
  ],

之后:

“paths": {},
© www.soinside.com 2019 - 2024. All rights reserved.