【发布时间】:2016-04-01 20:52:16
【问题描述】:
如何在 Visual Studio Code 中成功配置和调试 Angular2 TypeScript 应用程序?
我也尝试过导入es6-shim 和reflect-metadata,但没有成功。相关代码如下。如果您需要更多详细信息,请告诉我。
注意:我使用的是 Angular2 Beta。
错误信息
Debugger listening on port 24565
c:\Users\LeviF\OneDrive\Source Code\Github\SimpleMarket\app\bin\boot.js:1
System.register(['angular2/platform/browser', './app.component'], function(exports_1) {
^
ReferenceError: System is not defined
at Object.<anonymous> (c:\Users\LeviF\OneDrive\Source Code\Github\SimpleMarket\app\bin\boot.js:1:1)
at Module._compile (module.js:399:26)
at Object.Module._extensions..js (module.js:406:10)
at Module.load (module.js:345:32)
at Function.Module._load (module.js:302:12)
at Module.runMain [as _onTimeout] (module.js:431:10)
at Timer.listOnTimeout (timers.js:93:15)
index.html
<html>
<head>
<title>Angular 2 QuickStart</title>
<!-- 1. Load libraries -->
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/es6-shim/es6-shim.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>
<!-- 2. Configure SystemJS -->
<script>
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
System.import('app/bin/boot')
.then(null, console.error.bind(console));
</script>
<script>
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
</body>
</html>
boot.ts
//import 'reflect-metadata';
// import 'es6-shim';
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
// This loads our AppComponent as the ROOT Component (The app entry point)
bootstrap(AppComponent);
app.component.ts
import {Component} from 'angular2/core';
import {StockComponent} from './stock/stock.component';
@Component({
selector: 'my-app',
templateUrl: 'app/src/app.view.html',
directives: [StockComponent]
})
export class AppComponent{
public name: string;
getStock(){
this.name = "hello";
console.log('trying');
}
}
Launch.json
{"version": "0.2.0",
"configurations": [
{
"name": "Launch type",
"type": "node",
"program": "app/src/boot.ts",
"stopOnEntry": true,
"sourceMaps": true,
"outDir": "app/bin"
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 3000
}
]
}
【问题讨论】:
-
node_modules/systemjs/dist/system.src.js 是文件的有效位置吗?你是用 npm 包管理器安装的吗?
-
是的,我确实是通过 npm 安装的。该应用程序通过
npm start运行良好,并且仅在尝试通过“调试模式”启动时遇到错误。
标签: debugging typescript angular visual-studio-code