Phantomjs: Problems with web-animations-js

Created on 22 Apr 2016  路  14Comments  路  Source: ariya/phantomjs

  1. Which version of PhantomJS are you using? Tip: run phantomjs --version.
    version 2.1.1
  2. What steps will reproduce the problem?

    1. Testing with KarmaJS

  3. Which operating system are you using?
    Mac OS X 10.11.4
  4. Did you use binary PhantomJS or did you compile it from source?
    npm install
  5. Please provide any additional information below.
    -- Polymer needs web-animations-js, when I run grunt with karma test, i got the problem below.

Running "karma:unit" (karma) task
22 04 2016 09:59:13.604:INFO [karma]: Karma v0.13.22 server started at http://localhost:9876/
22 04 2016 09:59:13.608:INFO [launcher]: Starting browser PhantomJS
22 04 2016 09:59:15.324:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#uU9q97xdPGoxyFRKAAAA with id 26128362
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
TypeError: undefined is not a constructor (evaluating 'b.animate({opacity:["1","0"]},{duration:1,fill:"forwards"})')
at [...project path...]/dist/bower_components/web-animations-js/web-animations.min.js:16

stale

Most helpful comment

I pretty much had the same issue as described her when i updated angular cli to 1.0.0 and angular to 4.0.1 today.

This is the solution i came up with, which seems to work so i wanted to briefly how i managed to solve it.

I created a new project with angular cli and saw that the polyfill.ts template has changed:

/**
 * 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`.

as you can see there is a new entry for web-animations which i uncommented (as well as most of the other polyfills):

/**
 * 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`.

Afterwards i removed the web-animations from my script section in .angular-cli.json

Then all my tests ran already, besides the one where the component actually uses animations.
To solve this, i import the NoopAnimationsModule and it works :)

import { TestBed, async } from '@angular/core/testing';

import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { animationPlayerFactory } from './animation-player.factory';

import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      import: [
        NoopAnimationsModule
      ],
      declarations: [
        AppComponent
      ],
    }).compileComponents();
  }));

  // tests...

});

This pretty much solved the problem. Now for me it would be interesting if this also works for you and if you think thus is a "proper" solution.

Thanks and best regards,
Matthias

All 14 comments

Any News about this issue?

i have the same problem.

phantomjs version 3.10.8
install with npm install
in windows 10 x64

D:\Code\WebstormProjects\JWFrontPage>karma start --single-run --browsers PhantomJS --colors false
09 12 2016 22:34:39.797:WARN [karma]: Port 9876 in use
09 12 2016 22:34:39.804:INFO [karma]: Karma v1.3.0 server started at http://localhost:9877/
09 12 2016 22:34:39.805:INFO [launcher]: Launching browser PhantomJS with unlimited concurrency
09 12 2016 22:34:39.819:INFO [launcher]: Starting browser PhantomJS
09 12 2016 22:34:57.432:INFO [PhantomJS 2.1.1 (Windows 8 0.0.0)]: Connected on socket /#kwb0UZY9zWr1PUBwAAAA with id 27118687
PhantomJS 2.1.1 (Windows 8 0.0.0) LOG: 'Attempting to configure 'style' with descriptor '{"enumerable":true,"configurable":true}' on object '[object HTMLHtmlElement]' and got error, giving up: TypeError: At
tempting to configurable attribute of unconfigurable property.'

PhantomJS 2.1.1 (Windows 8 0.0.0) ERROR
  TypeError: undefined is not a constructor (evaluating 'b.style._set(a.propertyName(c),d)')
  at webpack:///D:/Code/WebstormProjects/JWFrontPage/~/web-animations-js/web-animations-next.min.js:15:0 <- src/test.ts:91929
PhantomJS 2.1.1 (Windows 8 0.0.0): Executed 3 of 48 ERROR (0.787 secs / 0.876 secs)

i need this to run test angular2 project in teamcity.
now, i cannot test project in teamcity untill this problem solution.

To get this working:
Modify your karma.conf.js in local project setup and add './node_modules/web-animations-js/web-animations.min.js' to the files section.

This solution does not resolve issue in phantomjs - just a work around to get karma test to pass without the error described in the above 2 comments.

Example:

    files: [
      './node_modules/intl/locale-data/jsonp/en-US.js',
      './node_modules/web-animations-js/web-animations.min.js',
      { pattern: './src/test.ts', watched: false }
    ],

@kevinkray

Not working for me. Why should that solve the problem?

See
https://github.com/Maistho/karma-web-animations-phantomjs/tree/kevinkray-solution

@Maistho the above fix would only be for the karma.config.js file in the local projects that use PhantomJS and animation polyfill that are described by @julrod092 and @Lyoko-Jeremie .

@kevinkray

Your fix also does not work for me, can you explain why this should solve the problem/offer any other advice?

I am using "web-animations-js": "^2.2.2" & "phantomjs-prebuilt": "^2.1.14"
I have the exact error described by everyone above.

Pinning web-animations-js to 2.1.5 appears to get around this issue for me.

I pretty much had the same issue as described her when i updated angular cli to 1.0.0 and angular to 4.0.1 today.

This is the solution i came up with, which seems to work so i wanted to briefly how i managed to solve it.

I created a new project with angular cli and saw that the polyfill.ts template has changed:

/**
 * 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`.

as you can see there is a new entry for web-animations which i uncommented (as well as most of the other polyfills):

/**
 * 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`.

Afterwards i removed the web-animations from my script section in .angular-cli.json

Then all my tests ran already, besides the one where the component actually uses animations.
To solve this, i import the NoopAnimationsModule and it works :)

import { TestBed, async } from '@angular/core/testing';

import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { animationPlayerFactory } from './animation-player.factory';

import { AppComponent } from './app.component';

describe('AppComponent', () => {
  beforeEach(async(() => {
    TestBed.configureTestingModule({
      import: [
        NoopAnimationsModule
      ],
      declarations: [
        AppComponent
      ],
    }).compileComponents();
  }));

  // tests...

});

This pretty much solved the problem. Now for me it would be interesting if this also works for you and if you think thus is a "proper" solution.

Thanks and best regards,
Matthias

@mscu Huh. I could actually make it work just by reordering my polyfills, importing web-animations before zonejs. I guess it makes sense since zonejs patches some browser APIs. 馃槙

Thanks for the info anyway!

@Maistho re-ordering I think has worked for me too. still verifying but it is working in many of the cases so far.

Re-ordering the imports to import web-animations-js before zone.js worked for me.

for me, web-animations-js was already declared before zone.js but still not working.

mscu's solution did the trick for me. I think importing NoopAnimationsModule is the key (which makes sense)

I had the same issue and what fixed it for me was changing the order of my imports. I have a couple of custom modules that rely on animations through Angular Material originally I had something like this

imports: [
....,
NoopAnimationsModule,
MyModule1,
MyModule2
]

None of the other solutions worked, but moving NoopAnimationsModule import to the bottom of the list, solved the problem for me

imports: [
....,
MyModule1,
MyModule2,
NoopAnimationsModule
]

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

julmot picture julmot  路  5Comments

machadolab picture machadolab  路  5Comments

maboiteaspam picture maboiteaspam  路  3Comments

mdominado picture mdominado  路  3Comments

Snowlav picture Snowlav  路  3Comments