未处理的承诺拒绝:Zone.js

时间:2017-03-07 02:16:16

标签: node.js angular promise unhandled zone.js

我一直在开发人员工具中遇到这个错误,过去几天它一直让我精神错乱。

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

所以我已经阅读并尝试了几乎任何与修复涉及Zone.js的Unhandled Promise拒绝错误相关的事情都无济于事。 所有错误似乎都指向我的shim.min.js文件,但似乎无论我在错误中加载文件的顺序仍然存在!

以下是我的所有相关文件:

Index.html

karma.config.js

这是我的polyfill.ts文件:

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

这是我的test.ts文件:

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();

如果您还有其他想要查看的文件,请告诉我们!

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

通过从我的Index.html文件中删除以下内容解决了该问题:

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

这是加载了另一个zone.js实例,它覆盖了第一个实例并导致了未处理的promise。希望这有助于某人!