最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Angular8升級至Angular13遇到的問題解決

 更新時間:2023年01月28日 12:11:41   作者:前端小陽仔  
這幾天升級公司的一個Angular項目遇到了一些問題,下面這篇文章主要給大家介紹了關(guān)于Angular8升級至Angular13遇到的問題解決,文中介紹的非常詳細,需要的朋友可以參考下

前言

根據(jù)項目需求,需要把Angular版本從8升級到13,無法從8直接升至13,需要一級一級的升級,本文介紹了在升級Angular版本的時候的一種報錯和解決辦法。

一、開始之前

首先確保你 Node.js >= 12.20

創(chuàng)建新的分支,或者使用其他方式備份當前項目

刪除項目下 yarn.lock 或 package-lock.jso

二、升級步驟(一級一級的升級) 升級相關(guān)依賴

  1. 升級相關(guān)依賴
    前往 update.angular.io 將項目升級到 Angular (9-13版本)。
  2. 如果你有單獨使用 @angular/cdk 請執(zhí)行 ng update @angular/cdk@(9-13版本)
  3. 升級 NG-ZORRO,運行 ng update ng-zorro-antd@(9-13版本)
  4. 升級 NG-ALAIN,運行 ng update ng-alain(9-13版本)

三、常見問題

錯誤1:WARNING in xxx is part of the TypeScript compilation but it’s unused.Add only entry points to the ‘files’ or ‘include’ properties in your tsconfig.

// 在exclude后加上以下信息
 "files": ["../src/main.ts", "../src/polyfills.ts"],
 "include": ["src/**/*.d.ts"]
錯誤2:Repository is not clean. Please commit or stash any changes before updating.
ng update --all  --force --allow-dirty
錯誤3: Package ‘@angular/core’ is not a dependency…

類似以上錯誤重新安裝依賴

npm i
錯誤4:ERROR in ./src/styles.less (./node_modules/css-loader/dist/cjs.js??ref–14-1!./node_modules/postcss-loader/src??embedded!./node_modules/less-loader/dist/cjs.js??ref–14-3!./src/styles.less) Module build failed (from ./node_modules/less-loader/dist/cjs.js):@import ‘~@delon/theme/styles/index’;Can’t resolve ‘@delon/theme/styles/index.less’ in ‘xxx;in xxx\src\styles.less (line 2, column 0);@import ‘~@delon/theme/styles/default’;Can’t resolve ‘@delon/theme/styles/default.less’ in ‘xxx\src\app\layout\passport’

路徑有變化, 把 @import ‘~@delon/theme/styles/index’; 多余的一層目錄去掉:styles 報錯的目錄文件均需要去除多余目錄

如果路徑對著,但是還報如下錯誤:

angular.json未配置樣式路徑導(dǎo)致:

"stylePreprocessorOptions": {
  "includePaths": [
    "node_modules/"
  ]
}
錯誤5 src/app/layout/default/header/components/taskmange.component.ts:33:28 – error NG1001: @ViewChild options must be an object literal @ViewChild(“taskDrawer”, null) taskDrawer;

原因:ViewChild需要兩個參數(shù),并沒有提供opts

官網(wǎng)解釋:

static – whether or not to resolve query results before change detection runs (i.e. return static results only). If this option is not provided, the compiler will fall back to its default behavior, which is to use query results to determine the timing of query resolution. If any query results are inside a nested view (e.g. *ngIf), the query will be resolved after change detection runs. Otherwise, it will be resolved before change detection runs.

此段解釋在中文文檔中并沒有被翻譯,大體意思如下:

static – 是否在更改檢測運行之前解析查詢結(jié)果(即只返回靜態(tài)結(jié)果)。如果不提供此選項,編譯器將退回到其默認行為,即使用查詢結(jié)果來確定查詢解析的時間。如果任何查詢結(jié)果位于嵌套視圖中(例如*ngIf),則在運行更改檢測后將解析該查詢。否則,它將在變更檢測運行之前被解析。

@ViewChild("taskDrawer", {static: true}) taskDrawer;
 
 // 或者
 @ViewChild("taskDrawer", {static: false}) taskDrawer;
 
// 或者 
 @ViewChild("taskDrawer") taskDrawer;

根據(jù)官方提供的,不同場景設(shè)置。

錯誤6:樣式不見了
// angular.json 文件引入
"styles": [
	 "src/styles.less",
     "./node_modules/ng-zorro-antd/ng-zorro-antd.min.css"
],
// styles.less文件引入
@import '~ng-zorro-antd/ng-zorro-antd.less';
@import '~ng-zorro-antd/style/entry.less'; /* 引入基本樣式 */
@import '~ng-zorro-antd/button/style/entry.less'; /* 引入組件樣式 */
錯誤7:ERROR in src/app/core/i18n/i18n.service.ts:13:24 – error TS2307: Cannot find module ‘date-fns/locale/en’.13 import * as df_en from ‘date-fns/locale/en’;
import { enUS as dfEn, zhCN as dfZhCn, zhTW as dfZhTw, vi as dfVi } from 'date-fns/locale';
錯誤8: import { STColumn, STComponent, STReq, STRequestOptions, STRes } from ‘@delon/abc/table’;
// https://github.com/ng-alain/ng-alain/issues/1569 里有說明路徑變化,更改即可
import { STColumn, STComponent, STReq, STRequestOptions, STRes } from '@delon/abc/st';
錯誤9:error TS2307: Cannot find module ‘date-fns/distance_in_wor,import * as distanceInWordsToNow from ‘date-fns/distance_in_words_to_now’;
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
錯誤10:polyfills.js:7568 Unhandled Promise rejection: R3InjectorError(AppModule)[ApplicationModule -> ApplicationRef ->ApplicationInitStatus -> InjectionToken Application Initializer -> [object Object] -> StartupService -> ACLService -> ACLService ->ACLService]:NullInjectorError: No provider for ACLService! ; Zone: ; Task: Promise.then ; Value: NullInjectorError: R3InjectorError(AppModule)[ApplicationModule -> ApplicationRef -> ApplicationInitStatus -> InjectionToken Application Initializer -> [object Object] ->StartupService -> ACLService -> ACLService -> ACLService]:NullInjectorError: No provider for ACLService!
// 仔細看錯誤發(fā)現(xiàn)No provider for ACLService,則在app.module.ts中引入 ACLService ,缺什么引什么
  providers: [
    // 略
    ACLService,
    AlainConfigService,
  ],
錯誤11:Package ‘@angular/core’ is not a dependency…
npm i
錯誤12:ERROR in Failed to list lazy routes: Unknown module ‘E:/xxx/src/app/app.module#AppModule’.
錯誤12:ERROR in Failed to list lazy routes: Unknown module ‘E:/xxx/src/app/app.module#AppModule'.
錯誤13:Angular11 升級報錯:Angular Forms error: Two incompatible decorators on class

在Google搜索了解決辦法,發(fā)現(xiàn)遇到這種情況的人不少,但是都沒有明確的解決辦法,或者解決辦法在本項目不適用。隨后查閱了Angular的文檔,發(fā)現(xiàn)通過以下方法可以解決問題。

在tsconfig.json中添加以下代碼:

{
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  },
}
錯誤14:typescript不兼容問題 @angular/compiler-cli@8.0.3 requires a peer of typescript@>=3.4 ??.5 but none is installed. You must install peer dependencies yourself.

解決辦法:

安裝兼容版本

運行命令

npm i typescript@3.4.3
錯誤15:import { NzMessageService, UploadFile } from ‘ng-zorro-antd’;

組件導(dǎo)入路徑發(fā)生了變化

import { NzMessageService } from 'ng-zorro-antd/message';
import { NzUploadFile } from 'ng-zorro-antd/upload';
錯誤16:import { NzModalService } from ‘ng-zorro-antd’;

組件導(dǎo)入路徑發(fā)生了變化

import { NzModalService } from 'ng-zorro-antd/modal';
錯誤17:自定義主題色不起作用

angular.json 刪除引入的組件主題色

src/styles.less 里引入預(yù)定義主題文件

@import "../node_modules/ng-zorro-antd/ng-zorro-antd.less";
 
@import './styles/theme';
@import './styles/index';
錯誤18:Can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’

使用 Reactive Forms 需要額外引入 ReactiveFormsModule,可以參考官方文檔(https://angular.io/guide/reactive-forms)。

錯誤19:Angular12報錯(resize-observer-polyfill) TS2717:Property contentRect must be of type DOMRectReadOnly

解決辦法:

(1) 由于報錯的是第三方類庫,只能等待第三方類庫去修復(fù)該錯誤。

(2) 在第三方修復(fù)之前,可以禁用第三方類庫的檢查。

在項目根目錄的 TS 配置文件 tsconfig.json 中新增 skipLibCheck 屬性。

{
  "compilerOptions": {
 	。。。。。。
 
    "skipLibCheck": true   <---- 增加該配置
  }
}
錯誤20:

解決方案:npm install --save-dev raw-loader

{
  "compilerOptions": {
 	。。。。。。
 
    "skipLibCheck": true   <---- 增加該配置
  }
}
錯誤21:多次注入

platformBrowserDynamic被多次注入(一般為main.ts和app.module.ts),刪除多余的,保留一個,可以刪App.module.t

錯誤22:angular 從11.x更新到12.x 收到DON‘T USE IT FOR PRODUCTION!警告

angular從11.x版本升級到12.x版本后,會收到

This is a simple server for use in testing or debugging Angular applications locally.
It hasn’t been reviewed for security issues.

DON’T USE IT FOR PRODUCTION!

的警告,除了升級其他的并未修改,11.x版本的運行ng serve并沒有這個警告。

我是升級到12.2.17版本的,重新運行:

ng update @angular/cli --migrate-only --from=11.2.0 --to=12.2.17

運行后在ng serve那個警告就消失了

錯誤23:Git無法提交(Must use import to load ES Module: /Users/cipchk/Desktop/work/ng-alain/node_modules/@angular/compiler/fesm2015/compiler.mjs)

升級步驟是逐步運行,每一步都需要 git commit,注釋掉 .husky/pre-commit 中的 npx 開頭的行,在升級完成后再次打開。

錯誤24:An unhandled exception occurred: Directory import ‘/media/fuchaoyang/f5558d47-6c02-44ae-89da-2817f50425cf/angular12/licadmin/node_modules/@angular-devkit/build-angular/src/dev-server’ is not supported resolving ES modules

版本不兼容所致

// 升級前
"@angular-devkit/build-angular": "~12.2.18" 
// 升級后
"@angular-devkit/build-angular": "~13.3.9",
錯誤25:export ‘startWith’ (imported as ‘startWith’) was not found in ‘rxjs’

rxjs版本過低所致,升級版本

// 升級前
 "rxjs": "~6.5.3"
 
// 升級后
"rxjs": "~7.5.0"
錯誤26:Error: src/app/routes/dtreportmodule/data-report/pandect/pandect.component.ts:6:10 – error TS2305: Module ‘”@delon/chart”‘ has no exported member ‘G2TimelineData’.

組件路徑發(fā)生了變化

import { G2TimelineData } from '@delon/chart/timeline';
錯誤27:編譯后git出現(xiàn)了很多緩存編譯文件

更新目錄.gitignore文件增加如下忽略項:

# See http://help.github.com/ignore-files/ for more about ignoring files.
 
# Compiled output
/dist
/tmp
/out-tsc
/bazel-out
 
# Node
/node_modules
npm-debug.log
yarn-error.log
 
# IDEs and editors
.idea/
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace
 
# Visual Studio Code
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history/*
# Miscellaneous
/.angular/cache
.sass-cache/
/connect.lock
/coverage
/libpeerconnection.log
testem.log
/typings
# System files
.DS_Store
Thumbs.db
錯誤28:抽屜組件內(nèi)部自定義內(nèi)容無法展示

自定義ng-content 外面需要 包起來

錯誤29:antd-Table組件渲染數(shù)據(jù)時出現(xiàn)第一行空白行

antd table 加上 [nzScroll]=”{ x: ‘1500px’ }” 出現(xiàn)空白行

解決辦法:

:host ::ng-deep .ant-table-measure-now{
  // display: none;
  visibility: collapse;
}
30.報錯如下:

解決方式: 在tsconfig.json里新增”skipLibCheck”: true

總結(jié)

到此這篇關(guān)于Angular8升級至Angular13遇到的問題解決的文章就介紹到這了,更多相關(guān)Angular8升級Angular13問題內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Angularjs Promise實例詳解

    Angularjs Promise實例詳解

    Promise是一個構(gòu)造函數(shù),自己身上有all、reject、resolve這幾個異步方式處理值的方法,原型上有then、catch等同樣很眼熟的方法,下面通過實例代碼給大家講解angularjs promise 的相關(guān)知識,感興趣的朋友一起看看吧
    2018-03-03
  • 3個可以改善用戶體驗的AngularJS指令介紹

    3個可以改善用戶體驗的AngularJS指令介紹

    這篇文章主要介紹了3個可以改善用戶體驗的AngularJS指令,AngularJS是一款具有很高人氣的JavaScript框架,需要的朋友可以參考下
    2015-06-06
  • Angular請求防抖處理第一次請求失效問題

    Angular請求防抖處理第一次請求失效問題

    這篇文章主要介紹了angular請求防抖及處理第一次請求失效的相關(guān)資料,需要的朋友可以參考下
    2019-05-05
  • AngularJS 單元測試(二)詳解

    AngularJS 單元測試(二)詳解

    這篇文章主要介紹了AngularJS 單元測試(二)的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • angular實現(xiàn)表單驗證及提交功能

    angular實現(xiàn)表單驗證及提交功能

    這篇文章主要為大家詳細介紹了angular實現(xiàn)表單驗證及提交功能的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-02-02
  • AngularJS ng-controller 指令簡單實例

    AngularJS ng-controller 指令簡單實例

    本文主要介紹AngularJS ng-controller 指令,這里對ng-controller指令資料的整理,并附代碼示例和效果圖,有需要的朋友看下
    2016-08-08
  • AngularJS 的$timeout服務(wù)示例代碼

    AngularJS 的$timeout服務(wù)示例代碼

    這篇文章主要介紹了AngularJS 的$timeout服務(wù)示例代碼,需要的朋友可以參考下
    2017-09-09
  • Angularjs處理頁面閃爍的解決方法

    Angularjs處理頁面閃爍的解決方法

    這篇文章主要介紹了Angularjs處理頁面閃爍的解決方法,非常不錯,具有參考借鑒價值,需要的朋友可以參考下
    2017-03-03
  • Angular自定義指令Tooltip的方法實例

    Angular自定義指令Tooltip的方法實例

    現(xiàn)實世界千變?nèi)f化,區(qū)區(qū)幾種內(nèi)置指令不可能滿足所有的需求,下面這篇文章主要給大家介紹了關(guān)于Angular自定義指令Tooltip的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2022-05-05
  • 在?Angular?中獲取當前日期的方法

    在?Angular?中獲取當前日期的方法

    我們將通過示例介紹一種在 Angular 應(yīng)用程序中獲取當前日期的簡單方法,我們還將解決如何更改 Angular 中的日期格式,對在Angular中獲取當前日期感興趣的朋友跟隨小編一起看看吧
    2023-05-05

最新評論

锦屏县| 阿巴嘎旗| 静宁县| 景泰县| 廉江市| 江川县| 丘北县| 杭州市| 信阳市| 湘西| 观塘区| 兴化市| 永宁县| 东台市| 新龙县| 苗栗市| 乌鲁木齐市| 聊城市| 大荔县| 博罗县| 山东省| 福鼎市| 建宁县| 阿拉尔市| 锦州市| 康定县| 吉首市| 威远县| 星座| 黔西| 凤翔县| 柯坪县| 大安市| 虹口区| 潜江市| 江城| 长岭县| 商水县| 安宁市| 长治市| 宁波市|