gpt4 book ai didi

javascript - 最可能的原因是在 Zone.js 之后加载了 Promise polyfill(加载 zone.js 时不需要 Polyfilling Promise api

转载 作者:行者123 更新时间:2023-12-03 21:00:09 32 4
gpt4 key购买 nike

我得到的错误

            Error: Zone.js has detected that ZoneAwarePromise `(window|global).Promise` has been overwritten.
Most likely cause is that a Promise polyfill has been loaded after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. If you must load one, do so before loading zone.js.)
at Function.push../node_modules/zone.js/dist/zone.js.Zone.assertZonePatched (zone.js:58)
at new NgZone (core.js:24212)
at getNgZone (core.js:24925)
at PlatformRef.push../node_modules/@angular/core/fesm5/core.js.PlatformRef.bootstrapModuleFactory (core.js:24823)
at core.js:24867
at exceljs.min.js:3
at MutationObserver.n (exceljs.min.js:3)
at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runGuarded (zone.js:161)
at MutationObserver.<anonymous> (zone.js:144)

我从我收到此错误的地方发布了 zone.js 的一小部分
     function Zone(parent, zoneSpec) {
this._parent = parent;
this._name = zoneSpec ? zoneSpec.name || 'unnamed' : '<root>';
this._properties = zoneSpec && zoneSpec.properties || {};
this._zoneDelegate =
new ZoneDelegate(this, this._parent && this._parent._zoneDelegate, zoneSpec);
}
Zone.assertZonePatched = function () {
if (global['Promise'] !== patches['ZoneAwarePromise']) {
throw new Error('Zone.js has detected that ZoneAwarePromise `(window|global).Promise` ' +
'has been overwritten.\n' +
'Most likely cause is that a Promise polyfill has been loaded ' +
'after Zone.js (Polyfilling Promise api is not necessary when zone.js is loaded. ' +
'If you must load one, do so before loading zone.js.)');
}
};

上面的错误被抛出。我真的很努力地解决这个问题。

当我收到此错误时

我的项目中有一项任务是导出带有样式的 Excel 工作表。我找到了一个名为 exceljs 的包.包含此内容后,我开始收到此错误。

exceljs.js 自述文件中的一些相关文档
## ES5 Imports

要使用 ES5 转译的代码,请使用 dist/es5 路径。

const ExcelJS = require('exceljs/dist/es5');

注: ES5 版本隐式依赖于一些不再需要的 polyfill
由 exceljs 明确添加。
您需要将“core-js”和“regenerator-runtime”添加到您的依赖项中,并且
在 exceljs 导入之前,在您的代码中包含以下要求:

// polyfills required by exceljs
require('core-js/modules/es.promise');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('regenerator-runtime/runtime');

// ...

const ExcelJS = require('exceljs/dist/es5');

浏览器化

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/6.26.0/polyfill.js"></script>
<script src="exceljs.js"></script>

我正在使用es6。所以我错过了什么。请帮帮我。

Angular 版本详细信息。
            Angular CLI: 7.3.9
Node: 10.0.0
OS: linux x64
Angular: 8.0.0
... core

Package Version
-------------------------------------------------------------
@angular-devkit/architect 0.13.9
@angular-devkit/build-angular 0.13.9
@angular-devkit/build-optimizer 0.13.9
@angular-devkit/build-webpack 0.13.9
@angular-devkit/core 7.3.9
@angular-devkit/schematics 7.3.9
@angular/animations 7.2.15
@angular/cdk 8.1.4
@angular/cli 7.3.9
@angular/common 7.2.15
@angular/compiler 7.2.15
@angular/compiler-cli 7.2.15
@angular/forms 7.2.15
@angular/http 7.2.15
@angular/language-service 7.2.15
@angular/material 8.1.4
@angular/platform-browser 7.2.15
@angular/platform-browser-dynamic 7.2.15
@angular/router 7.2.15
@ngtools/webpack 7.3.9
@schematics/angular 7.3.9
@schematics/update 0.13.9
rxjs 6.3.3
typescript 3.2.4
webpack

最佳答案

到您提出问题时,您现在可能已经弄清楚了……从您的 polyfills.ts 中注释掉这一行

// import 'zone.js/dist/zone'; // Included with Angular CLI.

关于javascript - 最可能的原因是在 Zone.js 之后加载了 Promise polyfill(加载 zone.js 时不需要 Polyfilling Promise api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58602000/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com