[英]module resolution with angular2 / ASP.NET5 (cannot find angular2/core)
I have started a new ASP.NET5/MVC6 project. 我已经开始了一个新的ASP.NET5 / MVC6项目。
Attempt 1 My problem is that when I set moduleResolution
to classic
in tsconfig.json
i receive an error as follows: 尝试1我的问题是,当我设置moduleResolution
以classic
的tsconfig.json
如下我收到一个错误:
Cannot find module 'angular2/core' 找不到模块“ angular2 / core”
Attempt 2 If I change tsconfig.json
to use node
resolution, the exclude node_modules
in tsconfig.js
does not work, this is a bug? 尝试2如果我改变tsconfig.json
使用node
号决议,排除node_modules
在tsconfig.js
不工作, 这是一个错误? , which is closed, though it still seems to be a problem, and multiple errors are encountered when studio 2015 trolls through the node_modules
folder including every .d.ts
in the entire tree. ,虽然似乎仍是一个问题,但已关闭,但当Studio 2015 node_modules
文件夹(包括整个树中的每个.d.ts
时,会遇到多个错误。 There are hundreds of errors, mostly in rxjs
. 有数百个错误,其中大多数是rxjs
。
Attempt 3 If I remove tsconfig.json
completely, I can get the application executing, and the files compiled, but alas, this error in the browser. 尝试3如果完全删除tsconfig.json
,则可以使应用程序执行并编译文件,但可惜,浏览器中出现此错误。
Error: (SystemJS) require is not defined 错误:未定义(SystemJS)require
I cannot help but think that the angular2 / typescript support in Visual Studio is a complete mess , and I should go back to angular 1 and MVC5 . 我忍不住认为Visual Studio中对angular2 / typescript的支持是一团糟 ,我应该回到angular 1和MVC5 。 For the record, I am using typescript 2.0.6, and my visual studio is completely up to date. 作为记录,我使用的是打字稿2.0.6,而我的Visual Studio完全是最新的。
Is there a combination of
package.json
andtsconfig.json
that actually works out of the box with Visual Studio 2015 for angular2. 是否存在package.json
和tsconfig.json
的组合,该组合实际上可与Visual Studio 2015 for angular2一起使用。
package.json
has the following dependencies. 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
is as follows tsconfig.json
如下
{
"compilerOptions": {
"experimentalDecorators": true,
"moduleResolution": "classic"
},
"exclude": ["node_modules"]
}
boot.ts
is as follows 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 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.";
}
}
NB: Make certain that es6-shim.d.ts
is installed in the wwwroot directory. 注意:确保在wwwroot目录中安装了es6-shim.d.ts
。 Many of the node_modules
files traversed by typescript cannot be compiled without es6-shim.d.ts 没有es6-shim.d.ts,无法编译许多通过打字稿遍历的node_modules
文件
I have a sample on integrating angular2(2.1.0) and ASP.NET core, I think the ng2's packages dependencies will also work on ASP.NET5. 我有一个有关集成angular2(2.1.0)和ASP.NET核心的示例,我认为ng2的程序包依赖性也可以在ASP.NET5上运行。
systemjs.config.js systemjs.config.js
Hope it helps! 希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.