Angular 8应用兼容IE遇空白屏,需补充哪些配置?
The syntax errors you're seeing (related to class declarations) are the root cause here—IE 11 doesn't support ES6+ class syntax, so your code isn't being transpiled to ES5 correctly for older browsers. Let's walk through the fixes you need to apply:
1. Restore Core.js Polyfills
You mentioned removing all core.js imports, but that's a mistake. Even though Angular 8 uses core-js 3, IE 11 still needs polyfills for ES6+ features it doesn't natively support. Open your src/polyfills.ts file and uncomment all the core.js imports listed under the IE 11 section. They should look like this:
import 'core-js/es/array'; import 'core-js/es/date'; import 'core-js/es/function'; import 'core-js/es/map'; import 'core-js/es/number'; import 'core-js/es/object'; import 'core-js/es/parse-int'; import 'core-js/es/parse-float'; import 'core-js/es/regexp'; import 'core-js/es/set'; import 'core-js/es/string'; import 'core-js/es/symbol';
Keep the existing uncommented imports (classlist.js and web-animations-js) as those are still needed.
2. Fix Browserslist Configuration
Your browserslist currently has the required query commented out. Open your browserslist file and replace the commented line with an uncommented entry that explicitly includes IE 11. Remove the not dead part (since IE 11 is considered "dead" by default, which excludes it):
> 0.5% last 2 versions Firefox ESR IE 11
This tells the Angular build system to generate code compatible with IE 11.
3. Ensure ES5 Transpilation is Enabled
Angular 8 supports differential loading (generating both ES2015 and ES5 bundles), but we need to make sure the ES5 build is set up correctly:
- Check if you have a
src/tsconfig-es5.app.jsonfile. If not, create it with this content:{ "extends": "../tsconfig.json", "compilerOptions": { "target": "es5" } } - Open
angular.jsonand verify there's anes5configuration underarchitect > build > configurations:
If it's missing, add it."configurations": { "production": { ... }, "es5": { "tsConfig": "./src/tsconfig-es5.app.json" } }
4. Reinstall Dependencies and Rebuild
Run these commands to ensure all polyfills are installed and your app is rebuilt with the correct settings:
npm install ng serve --configuration=es5
Or for production builds:
ng build --configuration=production,es5
After applying these steps, your app should load correctly in IE 11 without the syntax errors.
内容的提问来源于stack exchange,提问作者James Barrett

