【问题标题】:Unhandled Promise rejection: Zone.js未处理的承诺拒绝:Zone.js
【发布时间】:2023-04-05 06:09:01
【问题描述】:

我在开发者工具中不断收到这个错误,在过去的几天里它一直在驱使我。

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

如果您想查看任何其他文件,请告诉我!

非常感谢任何帮助!

【问题讨论】:

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


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-31
      • 2023-03-17
      • 2018-04-01
      • 2021-09-19
      相关资源
      最近更新 更多