angular - Internet Explorer 和 Angular 6 错误错误 : Uncaught (in promise): Error: Loading chunk

标签 angular typescript internet-explorer angular6 internet-explorer-11

我在使用 angular 6 和 IE 11 时遇到问题,应用程序在 chrome 和其他浏览器中运行良好,但在 Internet Explorer 中,我得到了这个

ERROR Error: Uncaught (in promise): Error: Loading chunk default~app-xxxxx~eb5ba6d4 failed. (missing: http://localhost:4200/default~app-xxxx.js) Error: Loading chunk default~app-xxxx~eb5ba6d4 failed. (missing: http://localhost:4200/default~app-xxxx~eb5ba6d4.js)



项目详情

Angular CLI:6.2.3
节点:8.12.0
操作系统:win32 x64
Angular :
...

套餐版本

@angular-devkit/architect 0.8.3 @angular-devkit/core 0.8.3 @angular-devkit/schematics 0.8.3 @schematics/angular 0.8.3 @schematics/update 0.8.3 rxjs 6.2.2 typescript 2.9.2



我的应用程序路由是
const routes: Routes = [
    {
        path: '',
        loadChildren:  'app/content/pages/pages.module#PagesModule'

    },
    {
        path: 'layout',
        loadChildren: 'app/content/layout/layout.module#LayoutModule',      
    },
    {
        path: '**',
        redirectTo: ''
    }
];

最佳答案

投入几个小时后终于找到了我的解决方案
关于 promise((t,n) => 的问题,

  • 首先,打开 src/polyfills.ts 文件,并取消注释

  • /** IE9, IE10 and IE11 requires all of the following polyfills. **/
    // import 'core-js/es6/symbol';
    // import 'core-js/es6/object';
    // import 'core-js/es6/function';
    // import 'core-js/es6/parse-int';
    // import 'core-js/es6/parse-float';
    // import 'core-js/es6/number';
    // import 'core-js/es6/math';
    // import 'core-js/es6/string';
    // import 'core-js/es6/date';
    // import 'core-js/es6/array';
    // import 'core-js/es6/regexp';
    // import 'core-js/es6/map';
    // import 'core-js/es6/weak-map';
    // import 'core-js/es6/set';
    


    => lambda 表达式在 IE 中不支持,所以我们可以用代码 function() 代替这个表达式。
  • 安装一些包

    npm install --save web-animations-js

    npm install --save classlist.js

  • 然后我从 npm 包 (fuctbase64/index.js) 之一中发现了 promise 问题
    module.exports = function (event) {
      return new Promise((resolve, reject) => {
        let reader = new FileReader();
        let files = event.target.files;
        let len = files.length;
        if (len > 1) {
          reject(new DOMException("Only one file can be uploaded at a time"));
        } else {
          reader.onerror = () => {
            reader.abort();
            reject(new DOMException("Problem parsing input file."));
          };
          let file = files[0]
          reader.onload = (evt) => {
            const uint = new Uint8Array(evt.target.result);
            let bytes = [];
            uint.map(byte => {
              bytes.push(byte.toString(16));
            });
            const hex = bytes.join('').toUpperCase();
            let base64 = reader.result.split(',')[1];
            file.base64 = base64;
            file.binaryFileType = getMimetype(hex);
            resolve(file);
          };
          reader.readAsDataURL(file);
        }
      });
    }
    

    将代码替换为
    module.exports = function (event) {
      return new Promise(function(resolve, reject)  {
        let reader = new FileReader();
        let files = event.target.files;
        let len = files.length;
        if (len > 1) {
          reject(new DOMException("Only one file can be uploaded at a time"));
        } else {
          reader.onerror = function() {
            reader.abort();
            reject(new DOMException("Problem parsing input file."));
          };
          let file = files[0]
          reader.onload = function(evt){
            const uint = new Uint8Array(evt.target.result);
            let bytes = [];
            uint.map(function(byte) {
              bytes.push(byte.toString(16));
            });
            const hex = bytes.join('').toUpperCase();
            let base64 = reader.result.split(',')[1];
            file.base64 = base64;
            file.binaryFileType = getMimetype(hex);
            resolve(file);
          };
          reader.readAsDataURL(file);
        }
      });
    }
    

    关于angular - Internet Explorer 和 Angular 6 错误错误 : Uncaught (in promise): Error: Loading chunk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55180018/

    相关文章:

    javascript - 在 typescript 中扩展 Angular 全局对象

    javascript - 如何在 IE 的 Javascript 中获取当前日期?

    angular - 作为组件的输入变量的类型应该是什么 - Angular

    angular - Angular2 中的一种数据绑定(bind)方式

    javascript - Angular 允许在构造函数中继承服务声明

    angular - 使用 typescript (javascript)触发 ng-bootstrap Accordion 组件?

    IE中Json响应下载(7~10)

    HTML5 html5shiv 和 IE7

    Angular 2 数据持久化

    angular - polymer 纸元素属性和 Angular