2017-03-07 181 views
1

我一直在開發人員工具中發現這個錯誤,並且在過去的幾天裏我一直在思考。未處理的Promise拒絕:Zone.js

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

所以我已閱讀並試圖相當多的東西,一切有關解決這個涉及Zone.js無濟於事未處理的承諾廢品。 所有的錯誤似乎都指向我的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(); 

如果您還有其他任何想看的文件,請告訴我!

任何幫助非常感謝!

回答

0

這個問題是通過從我的index.html文件如下解決:

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

這是加載其覆蓋初審並導致未處理的承諾zone.js的另一個實例。希望這可以幫助別人!

相關問題