gpt4 book ai didi

未定义的 polyfills 的 Angular2 getOptional

转载 作者:太空狗 更新时间:2023-10-29 19:35:45 25 4
gpt4 key购买 nike

每当我尝试加载我的 ang2 应用程序时,我都会收到此错误。

angular2-polyfills.js:1243 TypeError: Cannot read property 'getOptional' of undefined
Error loading http://localhost:8081/app/boot.js
at _runAppInitializers (http://localhost:8081/node_modules/angular2/bundles/angular2.dev.js:12628:25)
at PlatformRef_._initApp (http://localhost:8081/node_modules/angular2/bundles/angular2.dev.js:12603:21)
at PlatformRef_.application (http://localhost:8081/node_modules/angular2/bundles/angular2.dev.js:12550:22)
at Object.bootstrap (http://localhost:8081/node_modules/angular2/bundles/angular2.dev.js:24805:64)
at execute (http://localhost:8081/app/boot.js:36:23)
at ensureEvaluated (http://localhost:8081/node_modules/systemjs/dist/system.src.js:3186:26)
at Object.execute (http://localhost:8081/node_modules/systemjs/dist/system.src.js:3304:13)
at doDynamicExecute (http://localhost:8081/node_modules/systemjs/dist/system.src.js:703:25)
at link (http://localhost:8081/node_modules/systemjs/dist/system.src.js:905:20)
at doLink (http://localhost:8081/node_modules/systemjs/dist/system.src.js:557:7)

我尝试在索引文件中添加和切换 shim es6 js 与其他脚本,但这没有帮助。在我从 repo 中提取最新版本后,此错误开始出现。我恢复到我自己的版本,因为我无法从我的同事那里找到任何会给我这个问题的更改,但不知何故错误并没有消失。他们的版本没有错误。我还尝试从 boot.ts 的 Bootstrap 中删除每个服务和提供程序。没有错误弹出。但是当我把那些提供者和策略放回去时,'getOptional of undefined' 又开始出现了。

/**
* boot.ts
*/

import {AppComponent} from './app.component';
import {bootstrap} from 'angular2/platform/browser';
import {HTTP_PROVIDERS} from "angular2/http";
import {ROUTER_PROVIDERS,RouteConfig,RouteParams,ROUTER_DIRECTIVES, LocationStrategy, HashLocationStrategy} from "angular2/router";
import {CardService} from "./game/card/card.service";
import {provide} from "angular2/core";
import {ThemeService} from "../app/game/theme/theme.service"
import {OrganisationService} from "./game/organisation/organisation.service";
import {UserService} from "./game/user/user.service";
import {SocketService} from "./helpercomponents/SocketService";
bootstrap(AppComponent,[
HTTP_PROVIDERS,
ROUTER_PROVIDERS, provide(LocationStrategy, {useClass: HashLocationStrategy}),
CardService,
ThemeService,
UserService,
OrganisationService
]);
<html>

<head>
<title>Kandoe</title>
<base href="/" />
<script src="./node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="./node_modules/systemjs/dist/system.src.js"></script>
<script src="./node_modules/rxjs/bundles/Rx.js"></script>
<script src="./node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="./node_modules/angular2/bundles/router.dev.js"></script>
<script src="./node_modules/angular2/bundles/http.dev.js"></script>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="./node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/dropzone.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/stomp.js/2.3.3/stomp.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sockjs-client/1.0.3/sockjs.js"></script>

<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="app/css/login-register.css">
<link rel="stylesheet" href="app/css/organisation-detail-browse.css">
<link rel="stylesheet" href="app/css/dropzone.css">
<link rel="stylesheet" href="app/css/game.css">
<link rel="stylesheet" href="app/css/circle-session.css">
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
</head>

<body>
<my-app>Loading...</my-app>
</body>

</html>

最佳答案

我无法确切地弄清楚原因是什么,但是在 tsconfig 中将 es6 更改为 es5 使其再次工作。

关于未定义的 polyfills 的 Angular2 getOptional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36106505/

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