Internet Explorer 11、Angular 8 和 SocketIO 兼容性
Internet Explorer 11, Angular 8 and SocketIO Compatibility
伙计们,我一直在搜索这个主题,到目前为止,我使用所有这些指南和 pollyfills 使 ie11 在 angular 8 上工作。
但是当我尝试添加 socketio 时,它在 IE11 上崩溃了,并且控制台显示
SCRIPT1002: Syntax error
File: vendor.js, Line: 70528, Column: 40
这是供应商代码
// The final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
let index = 0;
let lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, match => {
if (match === '%%') {
return;
} ... it goes and goes
我已经尝试了我发现的所有东西,但仍然没有得到任何线索,在 vendor.js 中它似乎与 css 有关,但是当我在 [中添加 socketio 时它会触发=40=].
我不太了解 angular 和浏览器的内部结构,我对 IE 和 Pollyfills 的支持相对较新,但在我的工作中需要。
你们知道我应该采取什么方法来解决这个问题。我没有找到更多关于这个问题的信息,据我了解 IE11 支持 websocket API.
这里是 angualar.json、pollyfills.ts 和 tsconfig.js
注意:它在 chrome、firefox、safari 上运行良好。
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"test": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/test",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "test:build"
},
"configurations": {
"production": {
"browserTarget": "test:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "test:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "test:serve"
},
"configurations": {
"production": {
"devServerTarget": "test:serve:production"
}
}
}
}
}},
"defaultProject": "test"
}
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags.ts';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
// import './zone-flags.ts';
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11 # For IE 9-11 support, remove 'not'.
------------------------ 编辑
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http://localhost:3000', options: {} };
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
SocketIoModule.forRoot(config) <--- this import fires ie11 error
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
```
刚刚通过将 socket.io-client
软件包降级到 package.json 中的版本 ~2.2.0
解决了同样的问题。
似乎从版本 2.3
开始,由于依赖项升级,ES5 支持已丢失。
有关详细信息,请参阅此 link:
https://github.com/socketio/socket.io-client/issues/1328
感谢您发布此信息 - 您帮助我确定了我自己的应用程序中的问题。
请不要将 socket.io-client
软件包降级到 2.2.0,因为存在内存泄漏:
Per-Message Deflate Memory Leak #1617
最初的问题来自软件包 debug
。
@socketio
的核心提交者 Damien Arrachequesne 建议使用 webpack-remove-debug
插件,直到“更好”的解决方案获得批准:
Please note that you can also use the webpack-remove-debug plugin...
你可以在这里找到它webpack-remove-debug
安装
npm install --save-dev webpack-remove-debug
配置
在您的 Webpack 1 配置中:
{
module: {
loaders: [
{
test: /\.js$/,
loader: 'webpack-remove-debug'
}
]
}
};
在您的 Webpack 2 配置中:
{
module: {
rules: [
{
test: /\.js$/,
loader: 'webpack-remove-debug'
}
]
}
};
我用 IE11 和 axios
测试了它,这取决于使用 debug
.
的 follow-redirects
PS。如果你对这一切发生的原因感兴趣,你可以查看 Qix 的回复:Transpile to ES5 #745
伙计们,我一直在搜索这个主题,到目前为止,我使用所有这些指南和 pollyfills 使 ie11 在 angular 8 上工作。
但是当我尝试添加 socketio 时,它在 IE11 上崩溃了,并且控制台显示
SCRIPT1002: Syntax error
File: vendor.js, Line: 70528, Column: 40
这是供应商代码
// The final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
let index = 0;
let lastC = 0;
args[0].replace(/%[a-zA-Z%]/g, match => {
if (match === '%%') {
return;
} ... it goes and goes
我已经尝试了我发现的所有东西,但仍然没有得到任何线索,在 vendor.js 中它似乎与 css 有关,但是当我在 [中添加 socketio 时它会触发=40=].
我不太了解 angular 和浏览器的内部结构,我对 IE 和 Pollyfills 的支持相对较新,但在我的工作中需要。
你们知道我应该采取什么方法来解决这个问题。我没有找到更多关于这个问题的信息,据我了解 IE11 支持 websocket API.
这里是 angualar.json、pollyfills.ts 和 tsconfig.js
注意:它在 chrome、firefox、safari 上运行良好。
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"test": {
"projectType": "application",
"schematics": {},
"root": "",
"sourceRoot": "src",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/test",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "test:build"
},
"configurations": {
"production": {
"browserTarget": "test:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "test:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.spec.json",
"karmaConfig": "karma.conf.js",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"tsconfig.app.json",
"tsconfig.spec.json",
"e2e/tsconfig.json"
],
"exclude": [
"**/node_modules/**"
]
}
},
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "test:serve"
},
"configurations": {
"production": {
"devServerTarget": "test:serve:production"
}
}
}
}
}},
"defaultProject": "test"
}
/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
* This file is divided into 2 sections:
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
* file.
*
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
*
* Learn more in https://angular.io/guide/browser-support
*/
/***************************************************************************************************
* BROWSER POLYFILLS
*/
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
import 'classlist.js'; // Run `npm install --save classlist.js`.
/**
* Web Animations `@angular/platform-browser/animations`
* Only required if AnimationBuilder is used within the application and using IE/Edge or Safari.
* Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0).
*/
import 'web-animations-js'; // Run `npm install --save web-animations-js`.
/**
* By default, zone.js will patch all possible macroTask and DomEvents
* user can disable parts of macroTask/DomEvents patch by setting following flags
* because those flags need to be set before `zone.js` being loaded, and webpack
* will put import in the top of bundle, so user need to create a separate file
* in this directory (for example: zone-flags.ts), and put the following flags
* into that file, and then add the following code before importing zone.js.
* import './zone-flags.ts';
*
* The flags allowed in zone-flags.ts are listed here.
*
* The following flags will work for all browsers.
*
* (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame
* (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick
* (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames
*
* in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js
* with the following flag, it will bypass `zone.js` patch for IE/Edge
*
* (window as any).__Zone_enable_cross_context_check = true;
*
*/
/***************************************************************************************************
* Zone JS is required by default for Angular itself.
*/
// import './zone-flags.ts';
import 'zone.js/dist/zone'; // Included with Angular CLI.
/***************************************************************************************************
* APPLICATION IMPORTS
*/
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"module": "esnext",
"moduleResolution": "node",
"importHelpers": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2018",
"dom"
]
},
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true
}
}
# This file is used by the build system to adjust CSS and JS output to support the specified browsers below.
# For additional information regarding the format and rule options, please see:
# https://github.com/browserslist/browserslist#queries
# You can see what browsers were selected by your queries by running:
# npx browserslist
> 0.5%
last 2 versions
Firefox ESR
not dead
IE 9-11 # For IE 9-11 support, remove 'not'.
------------------------ 编辑
import { SocketIoModule, SocketIoConfig } from 'ngx-socket-io';
const config: SocketIoConfig = { url: 'http://localhost:3000', options: {} };
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
SocketIoModule.forRoot(config) <--- this import fires ie11 error
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
```
刚刚通过将 socket.io-client
软件包降级到 package.json 中的版本 ~2.2.0
解决了同样的问题。
似乎从版本 2.3
开始,由于依赖项升级,ES5 支持已丢失。
有关详细信息,请参阅此 link:
https://github.com/socketio/socket.io-client/issues/1328
感谢您发布此信息 - 您帮助我确定了我自己的应用程序中的问题。
请不要将 socket.io-client
软件包降级到 2.2.0,因为存在内存泄漏:
Per-Message Deflate Memory Leak #1617
最初的问题来自软件包 debug
。
@socketio
的核心提交者 Damien Arrachequesne 建议使用 webpack-remove-debug
插件,直到“更好”的解决方案获得批准:
Please note that you can also use the webpack-remove-debug plugin...
你可以在这里找到它webpack-remove-debug
安装
npm install --save-dev webpack-remove-debug
配置
在您的 Webpack 1 配置中:
{
module: {
loaders: [
{
test: /\.js$/,
loader: 'webpack-remove-debug'
}
]
}
};
在您的 Webpack 2 配置中:
{
module: {
rules: [
{
test: /\.js$/,
loader: 'webpack-remove-debug'
}
]
}
};
我用 IE11 和 axios
测试了它,这取决于使用 debug
.
follow-redirects
PS。如果你对这一切发生的原因感兴趣,你可以查看 Qix 的回复:Transpile to ES5 #745