首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Internet 11、角8和SocketIO兼容性

Internet 11、角8和SocketIO兼容性
EN

Stack Overflow用户
提问于 2020-01-15 14:09:48
回答 2查看 1.2K关注 0票数 0

伙计们,我一直在搜索这个话题,到目前为止,我用所有这些指南和圆球填充使ie11在角度8上工作。

但是当我尝试添加socketio时,它只是在IE11上崩溃,控制台显示

代码语言:javascript
复制
SCRIPT1002: Syntax error 
File: vendor.js, Line: 70528, Column: 40

这是供应商代码

代码语言:javascript
复制
// 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的,但是当我在app.module.ts中添加套接字时,它会触发。

我对的内部特性不太了解,我对IE和Pollyfills的支持相对较新,但在我的工作中是需要的。

你们知道我该走哪条路来解决这个问题。我没有找到更多关于这个问题的信息,因为我理解IE11支持websocket。

这是angualar.json,pollyfills.ts和tsconfig.js

注意:它在chrome,firefox,safari上运行得很好。

代码语言:javascript
复制
{
  "$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"
}
代码语言:javascript
复制
/**
 * 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
 */
代码语言:javascript
复制
{
  "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
  }
}
代码语言:javascript
复制
# 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'.

-编辑

代码语言:javascript
复制
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 { }
代码语言:javascript
复制
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2020-01-27 18:29:08

通过将socket.io-client包降级为package.json中的~2.2.0版本,解决了同样的问题。

似乎从2.3版本开始,由于依赖关系升级而失去了ES5支持。有关详细信息,请参阅此链接:https://github.com/socketio/socket.io-client/issues/1328

谢谢你张贴这个-你帮助我找出了我自己的应用程序的问题。

票数 3
EN

Stack Overflow用户

发布于 2021-03-11 12:06:52

请不要仅仅将您的socket.io-client包降级为2.2.0,因为内存泄漏:每条消息显示内存泄漏#1617

最初的问题是从包debug开始。@socketio的核心提交者Damien Arrachequesne建议使用webpack-remove-debug插件,直到“更好”的解决方案获得批准:请注意,您也可以使用webpack-删除-调试插件.

你可以在这里找到它,webpack-删除-调试

安装

npm安装-保存-dev webpack-删除-调试

Configuration

在您的Webpack 1配置中:

代码语言:javascript
复制
{
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'webpack-remove-debug'
            }
        ]
    }
};

在您的Webpack 2配置中:

代码语言:javascript
复制
{
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'webpack-remove-debug'
            }
        ]
    }
};

我用IE11和axios进行了测试,后者依赖于使用debugfollow-redirects

PS。如果您对这一切发生的原因感兴趣,可以检查Qix:转到ES5 #745的响应。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59753146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档