【发布时间】:2016-09-20 13:51:31
【问题描述】:
我尝试在 ASP.NET MVC 5(非核心)应用程序中使用 Angular 2.0.0 和 JSMP、SystemJS 和 TS Loader。
Visual Studio 抱怨找不到 Angular 模块。
Severity Code Description Project File Line Suppression State
Error TS2307 Cannot find module './components/app.component'.
Error TS2307 Cannot find module '@angular/core'.
Error TS2307 Cannot find module '@angular/core'.
Error TS2307 Cannot find module '@angular/platform-browser'.
Error TS2307 Cannot find module '@angular/platform-browser-dynamic'.
我通过 JSPM 安装 Angular。
tsconfig.json
{
"compilerOptions": {
"target": "es5",
/* target of the compilation (es5) */
"module": "system",
/* System.register([dependencies], function) (in JS)*/
"moduleResolution": "node",
/* how module gets resolved (needed for Angular 2)*/
"emitDecoratorMetadata": true,
/* needed for decorators */
"experimentalDecorators": true,
/* needed for decorators (@Injectable) */
"noImplicitAny": false
/* any has to be written explicity*/
},
"exclude": [
/* since compiling these packages could take ages, we want to ignore them*/
"jspm_packages",
"node_modules"
],
"compileOnSave": false
/* on default the compiler will create js files */
}
config.js
System.config({
baseURL: "/",
defaultJSExtensions: true,
transpiler: "babel",
babelOptions: {
"optional": [
"runtime",
"optimisation.modules.system"
]
},
typescriptOptions: {
"tsconfig": true
},
paths: {
"github:*": "jspm_packages/github/*",
"npm:*": "jspm_packages/npm/*"
},
packages: {
"app": {
"main": "bootstrap",
"format": "system",
"defaultExtensions": "ts",
"meta": {
"*.ts": {
"loader": "ts"
}
}
}
},
map: {
"@angular/common": "npm:@angular/common@2.0.0",
"@angular/compiler": "npm:@angular/compiler@2.0.0",
"@angular/core": "npm:@angular/core@2.0.0",
"@angular/http": "npm:@angular/http@2.0.0",
"@angular/platform-browser": "npm:@angular/platform-browser@2.0.0",
"@angular/platform-browser-dynamic": "npm:@angular/platform-browser-dynamic@2.0.0",
"@angular/router": "npm:@angular/router@3.0.0",
"babel": "npm:babel-core@5.8.38",
"babel-runtime": "npm:babel-runtime@5.8.38",
"core-js": "npm:core-js@2.4.1",
"es6-shim": "github:es-shims/es6-shim@0.35.1",
"reflect-metadata": "npm:reflect-metadata@0.1.8",
"rxjs": "npm:rxjs@5.0.0-beta.12",
"ts": "github:frankwallis/plugin-typescript@5.1.2",
"zone.js": "npm:zone.js@0.6.23",
"github:frankwallis/plugin-typescript@5.1.2": {
"typescript": "npm:typescript@2.0.2"
},
}
});
app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './components/app.component';
@NgModule({
imports: [BrowserModule],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule { }
index.html
<script src="../../jspm_packages/npm/core-js@2.4.1/client/shim.min.js"></script>
<script src="../../jspm_packages/npm/zone.js@0.6.23/dist/zone.min.js"></script>
<script src="../../jspm_packages/npm/reflect-metadata@0.1.8/Reflect.js"></script>
<script src="../../jspm_packages/system.js"></script>
<script src="../../config.js"></script>
<script>
System.config
({
map: {
"@@angular/common": "npm:@@angular/common@2.0.0",
"@@angular/compiler": "npm:@@angular/compiler@2.0.0",
"@@angular/core": "npm:@@angular/core@2.0.0",
"@@angular/http": "npm:@@angular/http@2.0.0",
"@@angular/platform-browser": "npm:@@angular/platform-browser@2.0.0",
"@@angular/platform-browser-dynamic": "npm:@@angular/platform-browser-dynamic@2.0.0",
"@@angular/router": "npm:@@angular/router@3.0.0",
"reflect-metadata": "npm:reflect-metadata@0.1.8"
},
transpiler: "ts",
packages:
{
"app": {
"defaultExtension": "ts",
"meta": {
"*.ts": {
"loader": "ts"
}
}
}
}
});
console.log("System.Config Init OK");
</script>
【问题讨论】:
标签: angular typescript visual-studio-2015 systemjs jspm