Internet explorer & Angular 6 ERROR Error: Uncaught (in promise): Error: Loading chunk
Internet explorer & Angular 6 ERROR Error: Uncaught (in promise): Error: Loading chunk
我在使用 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
OS: 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: ''
}
];
我认为您需要添加一些 polyfill。如果打开 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';
编辑:
正如@Arikael 在评论中提到的,此列表下方可能列出了更多 polyfils,您可能也想取消注释。
您必须添加元标记。
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
你能从这里检查一下步骤吗?
this was the issue with IE
Angular CLI 应用程序需要更多步骤才能支持 Internet Explorer。
投入几个小时后终于找到了我的解决方案
关于 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)
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 中遇到有关 "loading chunk xyz module failed" 的错误。我尝试了很多东西但没有解决方案。
最后,我在 NgModule 定义中更改了 "declarations" 数组和 "imports" 数组的添加顺序。
我的意思是在 NgModule() 中的 "imports" 之前定义 "declarations" 解决了我的问题。
@NgModule({
declarations: [SomeComponent],
imports: [
FormsModule,
ReactiveFormsModule,
CommonModule,
MaterialModule,
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
useFactory: translateHttpLoaderFactory,
deps: [HttpClient]
}
})
]
})
This happens if a chunk could not be loaded, which will happen more often on mobile due to poor connections. You need to have some error handling in case a chunk failed to load, such as asking the user to reload the page.
我在使用 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 OS: 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: ''
}
];
我认为您需要添加一些 polyfill。如果打开 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';
编辑:
正如@Arikael 在评论中提到的,此列表下方可能列出了更多 polyfils,您可能也想取消注释。
您必须添加元标记。
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
你能从这里检查一下步骤吗? this was the issue with IE
Angular CLI 应用程序需要更多步骤才能支持 Internet Explorer。
投入几个小时后终于找到了我的解决方案 关于 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)
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 中遇到有关 "loading chunk xyz module failed" 的错误。我尝试了很多东西但没有解决方案。 最后,我在 NgModule 定义中更改了 "declarations" 数组和 "imports" 数组的添加顺序。 我的意思是在 NgModule() 中的 "imports" 之前定义 "declarations" 解决了我的问题。
@NgModule({
declarations: [SomeComponent],
imports: [
FormsModule,
ReactiveFormsModule,
CommonModule,
MaterialModule,
TranslateModule.forChild({
loader: {
provide: TranslateLoader,
useFactory: translateHttpLoaderFactory,
deps: [HttpClient]
}
})
]
})
This happens if a chunk could not be loaded, which will happen more often on mobile due to poor connections. You need to have some error handling in case a chunk failed to load, such as asking the user to reload the page.