每当我尝试加载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'开始再次出现。
/**
* 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>
&#13;
答案 0 :(得分:0)
我无法确切地知道原因是什么,但是在tsconfig中将es6更改为es5会使其再次运行。