0

Guys i've been searching about this topic, by far i make ie11 works on angular 8 with all these guides and pollyfills.

enter image description here

But when i try to add socketio, it just crash on IE11, and the console shows

SCRIPT1002: Syntax error 
File: vendor.js, Line: 70528, Column: 40

Here is the vendor code

// 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

i have tried all what i found, but still don't get a clue, in vendor.js it seems to be something about css, but it fires when i add socketio in the app.module.ts.

i don't know much about the internals of angular and browsers, i'm relatively new giving support to IE and Pollyfills, but is needed in my job.

you guys have any idea what path i should take to solve this. I didn't find more about this problem, as i understand IE11 support websocket API.

here is angualar.json, pollyfills.ts and tsconfig.js

NOTE: it works fine on 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'.

------------------------ EDIT

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 { }
```
  • Please check your code and [this link](https://stackoverflow.com/questions/56379067/how-do-i-support-internet-explorer-in-an-angular-8-application), whether you are using this method to make the angular 8 applications work well in IE browser. Because, I want to reproduce the problem using angular8 and [Socket.IO](https://socket.io/get-started/chat/), can you create a sample or give some tutorial or steps to reproduce the problem? – Zhi Lv Jan 15 '20 at 15:40
  • i've tried that befeore, by now i just jave a basic angular proyect no more than app.component, i just added ngx-socketio and a server in node.js(express). If i use any library of Socket, angular just stop rendering, on post edit: socket import in app.module – Alex Contreras Jan 15 '20 at 17:06
  • for reproduction 1- basic angular boilerplate (ng new app) 2- add polyfills for IE11 (all runs ok for now) 3- add socketio or ngx socketio (angular stop working on IE11) – Alex Contreras Jan 15 '20 at 17:15

2 Answers2

3

Just resolved the same issue by downgrading the socket.io-client package to version ~2.2.0 in package.json.

Seems like since version 2.3, ES5 support was lost due to a dependency upgrade. See this link for more details: https://github.com/socketio/socket.io-client/issues/1328

Thank you for posting this - you helped me identify the problem in my own app.

henrikrank
  • 131
  • 1
  • 2
0

Please don't just downgrade your socket.io-client package to 2.2.0, since there is an memory leak: Per-Message Deflate Memory Leak #1617

The initial problem is comming from the package debug. Damien Arrachequesne, the core committer from @socketio, recommended to use the webpack-remove-debug plugin until a "better" solution is approved: Please note that you can also use the webpack-remove-debug plugin...

You can find it here webpack-remove-debug

Install

npm install --save-dev webpack-remove-debug

Configuration

In your Webpack 1 config:

{
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'webpack-remove-debug'
            }
        ]
    }
};

In your Webpack 2 config:

{
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'webpack-remove-debug'
            }
        ]
    }
};

I tested it with IE11 and axios which depends on follow-redirects which uses debug.

PS. If you are interested why this all happened, you can check the response from Qix: Transpile to ES5 #745