簡體   English   中英

Webpacked Angular2 應用程序類型錯誤:無法讀取未定義的屬性“getOptional”

[英]Webpacked Angular2 app TypeError: Cannot read property 'getOptional' of undefined

我見過很多人有這個問題,有一個與 angular2-polyfills.js 相關的解決方案。 我已經在我的 webpack 中包含了這個文件,但是:

entry: {
    'angular2': [
        'rxjs',
        'zone.js',
        'reflect-metadata',
        'angular2/common',
        'angular2/core',
        'angular2/router',
        'angular2/http',
        'angular2/bundles/angular2-polyfills'
    ],
    'app': [
        './src/app/bootstrap'
    ]
}

盡管如此,我在嘗試加載我的根組件時遇到以下錯誤:

Cannot resolve all parameters for 'ResolvedMetadataCache'(?, ?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'ResolvedMetadataCache' is decorated with Injectable.

Uncaught TypeError: Cannot read property 'getOptional' of undefined

都來自dom_element_schema_registry:43 我究竟做錯了什么?

下面是有問題的組件文件。

import {Component} from 'angular2/core';
import {MapComponent} from './map/map.component';

declare var window: any;

var $ = require('jquery');
window.$ = $;
window.jQuery = $;

@Component({
    selector: 'app',
    template: require('./app.component.jade'),
    styles: [],
    directives: [MapComponent]
})
export class AppComponent {}

編輯這可能與我對 jade-loader 的使用有關; 當我切換到需要原始 HTML 文件時,出現不同的錯誤:

dom_element_schema_registry.ts:43 Uncaught EXCEPTION: Error during     instantiation of Token Promise<ComponentRef>!.
ORIGINAL EXCEPTION: RangeError: Maximum call stack size exceeded
ORIGINAL STACKTRACE:
RangeError: Maximum call stack size exceeded
    at ZoneDelegate.scheduleTask     (http://localhost:3000/angular2.bundle.js:20262:28)
    at Zone.scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20184:41)
    at scheduleResolveOrReject (http://localhost:3000/angular2.bundle.js:20480:16)
    at ZoneAwarePromise.then [as __zone_symbol__then] (http://localhost:3000/angular2.bundle.js:20555:19)
    at scheduleQueueDrain (http://localhost:3000/angular2.bundle.js:20361:63)
    at scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20369:11)
    at ZoneDelegate.scheduleTask (http://localhost:3000/angular2.bundle.js:20253:23)
    at Zone.scheduleMicroTask (http://localhost:3000/angular2.bundle.js:20184:41)
    at scheduleResolveOrReject (http://localhost:3000/angular2.bundle.js:20480:16)
    at ZoneAwarePromise.then [as __zone_symbol__then] (http://localhost:3000/angular2.bundle.js:20555:19)

當 2 個 zone 副本在同一個地方運行時會發生這種情況。 之前是 system-polyfill。

我在同時包含 zone.js 時遇到了同樣的問題。 當 2 zone 都監視所有 promise 調用時,它們會相互反彈並導致堆棧溢出。

angular-polyfill 始終包含 ng 自己的區域實現。 zone.js 不應單獨加載。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM