升级到 Ionic 5 后,TypeScript 编译中缺少 src/zone-flags.ts

Sha*_*wal 20 node.js typescript ionic-framework angular

我通过这两个命令升级了我的 Ionic 4 应用程序:

# Upgrading to Ionic 5
npm install @ionic/angular@latest @ionic/angular-toolkit@latest --save

# Upgrading to Angular 9
ng update @angular/core @angular/cli
Run Code Online (Sandbox Code Playgroud)

当我这样做时ionic serve,我开始收到此错误:

> ng run app:serve --host=localhost --port=8100
[ng] chunk {} 0.js, 0.js.map () 22.1 kB  [rendered]
[ng] chunk {common} common.js, common.js.map (common) 25.7 kB  [rendered]
[ng] 
[ng] ERROR in ./src/zone-flags.ts
[ng] Module build failed (from ./node_modules/@ngtools/webpack/src/index.js):
[ng] Error: /Users/shashank/Projects/my-app/mobile-app/src/zone-flags.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
[ng]     at AngularCompilerPlugin.getCompiledFile (/Users/shashank/Projects/my-app/mobile-app/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:909:23)
[ng]     at plugin.done.then (/Users/shashank/Projects/my-app/mobile-app/node_modules/@ngtools/webpack/src/loader.js:41:31)
[ng]     at process._tickCallback (internal/process/next_tick.js:68:7)
Run Code Online (Sandbox Code Playgroud)

Sha*_*wal 57

解决方法是更改​​以下行mobile-app/src/polyfills.ts

从:

import './zone-flags.ts';
Run Code Online (Sandbox Code Playgroud)

到:

import './zone-flags';
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,@elnezah。虽然我自己也找不到答案(一个小时左右),但查看错误后,我明白这与填充相关。所以我创建了一个新的 Angular & Ionic 应用程序,并将文件一一比较,发现了差异。 (2认同)