2

I keep getting this error in developer tools and its been driving me mental for the past few days.

Unhandled Promise rejection: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.

So I've read and tried pretty much anything and everything related to fixing this Unhandled Promise rejection error involving Zone.js to no avail. All the errors seem to be pointing at my shim.min.js file, but it seems that no matter what order I load my files in the error still persists!

Here are all my relevant files:

Index.html

karma.config.js

This is my polyfill.ts file:

import 'core-js/es6/reflect';
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';

This is my test.ts file:

import 'zone.js/dist/long-stack-trace-zone';
import 'zone.js/dist/proxy.js';
import 'zone.js/dist/sync-test';
import 'zone.js/dist/jasmine-patch';
import 'zone.js/dist/async-test';
import 'zone.js/dist/fake-async-test';
import { getTestBed } from '@angular/core/testing';
import {
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';

// Unfortunately there's no typing for the `__karma__` variable. Just declare it as any.
declare var __karma__: any;
declare var require: any;

// Prevent Karma from running prematurely.
__karma__.loaded = function () {};

// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
  BrowserDynamicTestingModule,
  platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);
// Finally, start Karma to run the tests.
__karma__.start();

If there are any other files youd like to see then just let me know!

Any help is much appreciated!

Waldo Rabie
  • 31
  • 1
  • 5

1 Answers1

1

The problem was resolved by removing the following from my Index.html file:

<!-- Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
    System.import('app').catch(function(err){ console.error(err); });
</script

This was loading another instance of zone.js which was overwriting the first instance and causing the unhandled promise. Hope this helps someone!

Waldo Rabie
  • 31
  • 1
  • 5