PHP技术那点事
全部
技术
PHP
MySQL
前端
Linux
JAVA
退出
编辑文章
选择分类
PHP
MySQL
前端
Linux
Java
工具
选择专栏
设计模式
java基础
Angular学习
Java面试题
描述:
封面图上传 :
+
点击上传图片
升级Angular9 报错 Uncaught TypeError: Cannot set property ɵfac of function XXX which has only a getter,具体如下: ```js ng-zorro-antd-mobile.js:10807 Uncaught TypeError: Cannot set property ɵfac of function ToastService(_appRef, _cfr, _zone) { this._appRef = _appRef; this._cfr = _cfr; ...
... } which has only a getter at ng-zorro-antd-mobile.js:10807 at Module../node_modules/ng-zorro-antd-mobile/__ivy_ngcc__/fesm5/ng-zorro-antd-mobile.js (ng-zorro-antd-mobile.js:10818) at __webpack_require__ (bootstrap:84) at Module../src/app/login/login.component.ts (login.component.ts:1) at __webpack_require__ (bootstrap:84) at Module../src/app/app-routing.module.ts (app-routing.module.ts:1) at __webpack_require__ (bootstrap:84) at Module../src/app/app.module.ts (app.module.ts:1) at __webpack_require__ (bootstrap:84) at Module../src/main.ts (main.ts:1) ``` #### 原因 升级Angular 9 后默认开启Ivy enableIvy=true, 在这个情况下使用es5是会报错的。我们需要把es5换成es2015 在tsconfig.json将 `"target": "es5"`换为`"target": "es2015"`,然后重新编译,运行成功 ``` { "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "downlevelIteration": true, "experimentalDecorators": true, "module": "esnext", "moduleResolution": "node", "importHelpers": true, "target": "es2015", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2018", "dom" ] }, "angularCompilerOptions": { "fullTemplateTypeCheck": true, "strictInjectionParameters": true } } ```
保存文章