本文介绍了Internet Explorer &Angular 6 错误错误:未捕获(承诺):错误:加载块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

ERROR Error: Uncaught (in promise): Error: Loading chunk默认~app-xxxxx~eb5ba6d4失败的.(缺失:http://localhost:4200/default~app-xxxx.js) 错误:加载块 default~app-xxxx~eb5ba6d4 失败.(丢失的:http://localhost:4200/default~app-xxxx~eb5ba6d4.js)

项目详情

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

软件包版本

@angular-devkit/architect 0.8.3@angular-devkit/core 0.8.3@angular-devkit/schematics 0.8.3@原理图/角度 0.8.3@原理图/更新0.8.3rxjs 6.2.2打字稿 2.9.2

我的应用路由是

const 路由:Routes = [{小路: '',loadChildren: 'app/content/pages/pages.module#PagesModule'},{路径:'布局',loadChildren: 'app/content/layout/layout.module#LayoutModule',},{小路: '**',重定向到:''}];
解决方案

经过几个小时的努力终于找到了我的解决方案关于 promise((t,n) => ,

的问题

  1. 首先打开src/polyfills.ts文件,取消注释
/** IE9、IE10 和 IE11 需要以下所有 polyfill.**///导入 'core-js/es6/symbol';//导入 'core-js/es6/object';//导入 'core-js/es6/function';//导入 'core-js/es6/parse-int';//导入 'core-js/es6/parse-float';//导入 'core-js/es6/number';//导入 'core-js/es6/math';//导入 'core-js/es6/string';//导入 'core-js/es6/date';//导入 'core-js/es6/array';//导入 'core-js/es6/regexp';//导入 'core-js/es6/map';//导入 'core-js/es6/weak-map';//导入 'core-js/es6/set';

=> lambda 表达式在 IE 中不支持,所以我们可以用代码 function() 代替这个表达式.

  1. 安装一些包

    npm install --save web-animations-js

    npm install --save classlist.js

然后我从 npm 包 (fuctbase64/index.js) 之一中发现了 promise 问题

module.exports = 函数(事件){返回新的承诺((解决,拒绝)=> {let reader = new FileReader();让文件 = event.target.files;让 len = files.length;如果 (len > 1) {拒绝(new DOMException("一次只能上传一个文件"));} 别的 {reader.onerror = () =>{reader.abort();拒绝(新的DOMException(解析输入文件时出现问题."));};让文件 = 文件 [0]reader.onload = (evt) =>{const uint = new Uint8Array(evt.target.result);让字节 = [];uint.map(byte => {bytes.push(byte.toString(16));});const hex = bytes.join('').toUpperCase();让 base64 = reader.result.split(',')[1];文件.base64 = base64;file.binaryFileType = getMimetype(hex);解决(文件);};reader.readAsDataURL(文件);}});}

替换代码

module.exports = 函数(事件){返回新的承诺(功能(解决,拒绝){let reader = new FileReader();让文件 = event.target.files;让 len = files.length;如果 (len > 1) {拒绝(new DOMException("一次只能上传一个文件"));} 别的 {reader.onerror = function() {reader.abort();拒绝(新的DOMException(解析输入文件时出现问题."));};让文件 = 文件 [0]reader.onload = 函数(evt){const uint = new Uint8Array(evt.target.result);让字节 = [];uint.map(函数(字节){bytes.push(byte.toString(16));});const hex = bytes.join('').toUpperCase();让 base64 = reader.result.split(',')[1];文件.base64 = base64;file.binaryFileType = getMimetype(hex);解决(文件);};reader.readAsDataURL(文件);}});}

I am getting issue while using angular 6 and IE 11, app is working fine in chrome & another browser but in internet explorer, i am getting this

Project details

Angular CLI: 6.2.3Node: 8.12.0OS: win32 x64Angular:...

Package Version

My app routing is

const routes: Routes = [
    {
        path: '',
        loadChildren:  'app/content/pages/pages.module#PagesModule'

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

After investing some hours finally found my solutionsIssue about promise((t,n) => ,

  1. At first, open the src/polyfills.ts file, and uncomment

=> lambda expression does not support in IE so we can replace with code function() instead of this expression.

  1. Install some packages

    npm install --save web-animations-js

    npm install --save classlist.js

Then i was found promise issue from one of the npm package (fuctbase64/index.js)

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);
    }
  });
}

Replace code with

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);
    }
  });
}

这篇关于Internet Explorer &Angular 6 错误错误:未捕获(承诺):错误:加载块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:25