gpt4 book ai didi

javascript - Webpack Angular 2 应用类型错误 : Cannot read property 'getOptional' of undefined

转载 作者:搜寻专家 更新时间:2023-10-30 21:53:29 25 4
gpt4 key购买 nike

我见过很多人遇到这个问题,解决方案与 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 个区域副本在同一个地方运行时会发生这种情况。之前是system-polyfill。

我在同时包含 zone.js 时遇到了同样的问题。当 2 zone 都监听所有的 promise 调用时,它们会相互反弹并导致堆栈溢出。

angular-polyfill 始终包含 ng 自己的区域实现。 zone.js 不应单独加载。

关于javascript - Webpack Angular 2 应用类型错误 : Cannot read property 'getOptional' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36401668/

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