我已經開始了一個新的ASP.NET5/MVC6項目。模塊分辨率與angular2/ASP.NET5(無法找到angular2/core)
嘗試1我的問題是,當我在tsconfig.json
設置moduleResolution
到classic
如下我收到一個錯誤:
Cannot find module 'angular2/core'
嘗試2如果我改變tsconfig.json
使用node
分辨率,排除node_modules
在tsconfig.js
不起作用,this is a bug?,這是關閉,雖然它似乎仍然是一個問題,並遇到多個錯誤時,演播室2015釣魚通過node_modules
文件夾includidi整個樹中的每個.d.ts
。有數百個錯誤,主要在rxjs
。
嘗試3如果我完全刪除tsconfig.json
,我可以在瀏覽器中執行應用程序並編譯文件,但是可能會出現此錯誤。
Error: (SystemJS) require is not defined
我不禁想,在Visual Studio 的angular2 /打字稿支持是一塌糊塗,我應該回到角1和MVC5。爲了記錄,我使用的是打字稿2.0.6,而我的視覺工作室完全是最新的。
Is there a combination of
package.json
andtsconfig.json
that actually works out of the box with 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.";
}
}
謝謝,我已經更新了.net核心,並且獲得了大部分應用程序,但需要一段時間才能完成,但這可能會有所幫助。在此期間,我正在留下一些更直接的答案。 – Jim
沒問題,歡迎您:) –
嗨,只是想知道es6-shim.d.ts扮演了什麼角色。es6-shim似乎是將它們全部掛在一起所需要的。在整個node_modules目錄中,我會在.d.ts文件中發現大量錯誤,直到es6-shim.d.ts放置在wwwroot的某處。 tsconfig.json的目標是es5,那麼爲什麼墊片是必要的? – Jim