[英]module resolution with angular2 / ASP.NET5 (cannot find angular2/core)
我已经开始了一个新的ASP.NET5 / MVC6项目。
尝试1我的问题是,当我设置moduleResolution
以classic
的tsconfig.json
如下我收到一个错误:
找不到模块“ angular2 / core”
尝试2如果我改变tsconfig.json
使用node
号决议,排除node_modules
在tsconfig.js
不工作, 这是一个错误? ,虽然似乎仍是一个问题,但已关闭,但当Studio 2015 node_modules
文件夹(包括整个树中的每个.d.ts
时,会遇到多个错误。 有数百个错误,其中大多数是rxjs
。
尝试3如果完全删除tsconfig.json
,则可以使应用程序执行并编译文件,但可惜,浏览器中出现此错误。
错误:未定义(SystemJS)require
我忍不住认为Visual Studio中对angular2 / typescript的支持是一团糟 ,我应该回到angular 1和MVC5 。 作为记录,我使用的是打字稿2.0.6,而我的Visual Studio完全是最新的。
是否存在
package.json
和tsconfig.json
的组合,该组合实际上可与Visual Studio 2015 for angular2一起使用。
package.json
具有以下依赖关系。
{
"version": "1.0.0",
"name": "asp.net",
"private": true,
"devDependencies": {
"angular2": "^2.0.0-beta.17"
},
"dependencies": {
"@types/angular2": "0.0.2",
"angular2": "^2.0.0-beta.17",
"es6-shim": "^0.35.1",
"gulp": "^3.9.1",
"gulp-jasmine": "^2.4.2",
"gulp-print": "^2.0.1",
"gulp-sass": "^2.3.2",
"gulp-typings": "^2.0.4",
"gulp-watch": "^4.3.10",
"karma": "^1.3.0",
"reflect-metadata": "^0.1.8",
"rxjs": "^5.0.0-rc.2",
"zone.js": "^0.6.26"
}
}
tsconfig.json
如下
{
"compilerOptions": {
"experimentalDecorators": true,
"moduleResolution": "classic"
},
"exclude": ["node_modules"]
}
boot.ts
如下
/// <reference path="../node_modules/angular2/core.d.ts"/>
// the above is a correct path, but it doesn't seem to matter.
import {bootstrap} from "angular2/platform/browser";
// ~~~~~~~~~~~~~~~~~~~~~~~~~ (Error Here)
import {HTTP_PROVIDERS} from "angular2/http";
import {AppComponent} from "./app.component";
bootstrap(AppComponent, [HTTP_PROVIDERS]);
console.log("starting angular...");
app.component.js
/// <reference path="../node_modules/angular2/core.d.ts"/>
import { Component, OnInit } from "angular2/core";
// ~~~~~~~~~~~~~ (Error Here)
@Component({
selector: "app",
templateUrl: "static.html"
})
export class AppComponent implements OnInit {
message: string;
constructor() {
console.log("starting app component");
}
ngOnInit() {
this
.message =
"The 'static.html' was used as the Angular2 'templateUrl'. There is a 'message' property bound to the <blockqoute> element.";
}
}
注意:确保在wwwroot目录中安装了es6-shim.d.ts
。 没有es6-shim.d.ts,无法编译许多通过打字稿遍历的node_modules
文件
我有一个有关集成angular2(2.1.0)和ASP.NET核心的示例,我认为ng2的程序包依赖性也可以在ASP.NET5上运行。
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.