angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

IE9 TypeError 'apply'

Open dricogit opened this issue 9 years ago • 30 comments

Bug Report or Feature Request (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.1 node: 7.9.0 os: win32 x64 @angular/animations: 4.1.0 @angular/common: 4.1.0 @angular/compiler: 4.1.0 @angular/core: 4.1.0 @angular/forms: 4.1.0 @angular/http: 4.1.0 @angular/platform-browser: 4.1.0 @angular/platform-browser-dynamic: 4.1.0 @angular/router: 4.1.0 @angular/cli: 1.0.1 @angular/compiler-cli: 4.1.0

Repro steps.

ng build --aot --prod tested on a real webserver

The log given by the failure.

In console of ie9 : TypeError: Object doesn't support property or method 'apply'

Desired functionality.

Works on ie9

Mention any other details that might be useful.

I tested with polyfills.ts ( core-js/es6 + classlist ). Also tested with shim.min.js, Typed Array, Blob, FormData from https://angular.io/docs/ts/latest/guide/browser-support.html

dricogit avatar Apr 27 '17 20:04 dricogit

@dricogit It's only issue in IE9? Is it working in other browsers?

sumitarora avatar Apr 27 '17 20:04 sumitarora

Works on ie10, ie11, firefox and chrome

dricogit avatar Apr 27 '17 20:04 dricogit

There's some other ie9 issues (https://github.com/angular/angular-cli/issues/4772) but it doesn't seem to be what you're experiencing, since you get it on a real web server.

filipesilva avatar May 05 '17 20:05 filipesilva

I am also getting this but, if I start with a very simple app created from Angular CLI it works fine, but as soon as I introduce routeing it stops working with this error.

SteveDrakey avatar May 12 '17 12:05 SteveDrakey

@filipesilva I have done a little more investigation 👍

repro

Create App ng new ie9test --routing

Edit Polyfills for IE9

Add two Components ng g c Test1 ng g c Test2

Add them to the routeing fix up imports etc.

const routes: Routes = [
  {
    path: '',
    children: [
      {
        path: 'test1',
        component: Test1Component
      },
      {
        path: 'test2',
        component: Test2Component
      }
    ]
  }
];

This will not work in IE9, you will see a big long list of ###### in the URL and the TypeError: Object doesn't support property or method 'apply' in the IE Console

To fix, edit app-routing.module and change the code as

@NgModule({
  imports: [
    RouterModule.forRoot(routes, { useHash: true })
    ],
  exports: [RouterModule]
})

Of course, it could be a different issue 😄

SteveDrakey avatar May 12 '17 12:05 SteveDrakey

My app also not work in IE9. Versions are similar to @dricogit . When I choose a file,IE9 report an error that SCRIPT438: 对象不支持“apply”属性或方法 vendor.bundle.js, 行19446 字符13 SCRIPT438: Object doesn't support property or method 'apply' vendor.bundle.js, Line 19446 Char13

My app code:

//upload-cert.component.ts
//choose file function
 selectedFileOnChanged(event:any) {`
    this.formErrors.certFormError = '';
    this.certName = event.target.value;
    this.certFile = event.target.files[0];

    if(this.certFile.size > 1024*1024*8){
      this.formErrors.certFormError = '文件大小上传大于8Mb。'
    }
    else if(this.certFile.type != "application/x-x509-ca-cert" && this.certFile.type != "application/x-pkcs12"){
      this.formErrors.certFormError = '必须上传.cer或.pfx后缀的证书';
    }
  }
//upload-cert.component.html
 <input type="file" (change)="selectedFileOnChanged($event)" id="upload_input"/>


//index.html   I also import some JS from https://angular.io/guide/browser-support
<script src="assets/js/shim.min.js"></script>
  <script src="assets/js/classList.min.js"></script>
  <script src="assets/js/Blob.js"></script>
  <script src="assets/js/formdata.js"></script>
  <script src="assets/js/Intl.min.js"></script>
  <script src="assets/js/typedarray.js"></script>
  <script src="assets/js/core.min.js"></script>
  <script src="assets/js/es6-shim.min.js"></script>
  <script src="assets/js/shims_for_IE.js"></script>
  <script src="assets/js/system-polyfills.js"></script>

//polyfills.ts
/**
 * 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/docs/ts/latest/guide/browser-support.html
 */

/***************************************************************************************************
 * BROWSER POLYFILLS
 */

/** 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/set';

/** IE10 and IE11 requires the following for NgClass support on SVG elements */
 import 'classlist.js';  // Run `npm install --save classlist.js`.

/** IE10 and IE11 requires the following to support `@angular/animation`. */
 import 'web-animations-js';  // Run `npm install --save web-animations-js`.


/** Evergreen browsers require these. **/
import 'core-js/es6/reflect';
import 'core-js/es7/reflect';


/** ALL Firefox browsers require the following to support `@angular/animation`. **/
 import 'web-animations-js';  // Run `npm install --save web-animations-js`.



/***************************************************************************************************
 * Zone JS is required by Angular itself.
 */
import 'zone.js/dist/zone';  // Included with Angular CLI.



/***************************************************************************************************
 * APPLICATION IMPORTS
 */

/**
 * Date, currency, decimal and percent pipes.
 * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
 */
 import 'intl';  // Run `npm install --save intl`.
/**
 * Need to import at least one locale-data with intl.
 */
 import 'intl/locale-data/jsonp/en';

//app.module.ts   I use HASH route
//angular
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

//bootstrap
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';

//fido
import { AppComponent } from './app.component';
import { LeftMenuComponent } from './common/left-menu/left-menu.component';
import { RightTabComponent } from './common/right-tab/right-tab.component';
import { NavTabComponent } from './common/nav-tab/nav-tab.component';
import { TabContactService } from './common/service/tab-contact.service';
import { ModalService } from "./common/modal/modal.service";
import { Test1Module } from './test1/test1.module';
import { Test2Module } from './test2/test2.module';
import { Test3Module } from './test3/test3.module';
import { WelcomePageModule } from './welcome-page/welcome-page.module';

//routes
import { appRoutes } from './app.routes';

//modal-component
import { ModalComponent } from "./common/modal/modal.component";

//3rd-module
import { FileUploadModule } from 'ng2-file-upload';

@NgModule({
  declarations: [
    AppComponent,
    LeftMenuComponent,
    RightTabComponent,
    NavTabComponent,
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    BrowserAnimationsModule,
    HttpModule,
    Test1Module,
    Test2Module,
    Test3Module,
    WelcomePageModule,
    FileUploadModule,
    NgbModule.forRoot(),
    RouterModule.forRoot(appRoutes , { useHash : true })

  ],
  providers: [ TabContactService, ModalService ],
  entryComponents: [ ModalComponent ],
  bootstrap: [AppComponent]
})
export class AppModule { }

So Why not work in IE9 ?

jianqiao0313 avatar Jun 21 '17 06:06 jianqiao0313

I have tried to uncomment all POLYFILLS (Angular 4), but I got the same issue on IE11. Here are error logs:

  • The error on console log: Unable to get property 'apply' of undefined or null reference
  • The error on catch: object doesn't support property or method 'json'

The code throw the error:

post(body: any, url: string = this.url): Promise<any> {
    let headers = new Headers({
      'Content-Type': 'application/json'
    });

    return this._http
      .post(url, JSON.stringify(body), { headers: headers })
      .toPromise()
      .then(res => res.json())
      .catch((err) => this.handleError(err));
  }

tamdao avatar Jun 28 '17 06:06 tamdao

any solution?

tamdao avatar Jul 01 '17 10:07 tamdao

@tamdao

From the code samples posted here I see they are at least missing a WeakMap polyfill (import 'core-js/es6/weak-map';). Also, I've found that web-animations-js breaks IE9. Also make sure you have the TypedArray/Blob/FormData polyfills. For TypedArray, I recommend import 'core-js/es6/typed';.

mafredri avatar Jul 01 '17 11:07 mafredri

@mafredri does not work. :D

tamdao avatar Jul 01 '17 14:07 tamdao

any solution?

tamdao avatar Jul 13 '17 09:07 tamdao

get the same problem "@angular/cli": "1.4.4" In console of ie9 : TypeError: Object doesn't support property or method 'apply' polyfills: import 'core-js/es6/symbol'; 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/date'; import 'core-js/es6/regexp'; import 'core-js/es6/object'; import 'core-js/es6/set'; import 'core-js/es6/weak-set'; import 'core-js/es6/map'; import 'core-js/es6/weak-map'; import 'core-js/es6/array'; import 'core-js/es6/string'; import 'core-js/es6/typed'

kravda avatar Oct 16 '17 20:10 kravda

import 'core-js/es6/symbol'; 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/regexp'; import 'core-js/es6/map'; import 'core-js/es6/weak-map'; import 'core-js/es6/set'; import 'core-js/es6/typed'; import 'core-js/es6/array'; import 'core-js/es6/object'; import 'core-js/es6/reflect'; import 'core-js/es7/reflect'; import 'zone.js/dist/zone';
import 'intl';

Having the same problem on IE9. We are trying to use Angular for our major e-commerce site and have lots of customers who are still on IE9. Anyone found the solution for this?

chikakow avatar Nov 06 '17 16:11 chikakow

keyword: Korean, resolved, zone.js, 0.8.4

저의 경우 IE9에서 subscribe를 호출할 때마다 TypeError: 'apply'가 발생 했습니다.

해당 문제를 zone.js 버전을 변경하여 해결을 했습니다.

result

// old package.json
 "dependencies": {
  ...
  "zone.js": "0.8.12"
  ...
 }
// change package.json
 "dependencies": {
  ...
  "zone.js": "^0.8.4"
  ...
 }

이렇게 변경하고난 후 부터 정상 작동하였습니다.

daehongKo avatar Nov 29 '17 04:11 daehongKo

Subscribe here. By this comment I suspect maybe this issue would be found in PathLocationStrategy

anysite avatar Dec 03 '17 13:12 anysite

I am not a user of the CLI and this issue still happens for me in IE9. This error may be from the @angular source.

steveblue avatar Dec 15 '17 23:12 steveblue

@anysite @tamdao @dricogit @SteveDrakey I just updated to 5.2.3 and the issue is gone now when using {useHash: true} in IE9. No TypeError, Routing works. Can you verify?

steveblue avatar Feb 01 '18 23:02 steveblue

I've faced this issue as well. Using ng serve I tried to dig around the unminified JS files and noticed the references of the apply function were being used in the console object. IE9 doesn't expose the console object unless the developer tools are open. I've added this polyfill - https://github.com/paulmillr/console-polyfill - and it seems to have solved the problem. Still, this might have only masked the actual problem/bug but might be of help for others.

idasbiste avatar Feb 14 '18 10:02 idasbiste

console-polyfill does not solve the problem for our build

steveblue avatar Feb 21 '18 19:02 steveblue

have same problem. solutions with fix version of zone.js or/and use console-polyfill did not help. but if add (and in advance install package web-animations-js) import 'web-animations-js'; have new error: SCRIPT5007: Object expected in main-client any ideas?

blackrek avatar Mar 15 '18 04:03 blackrek