【问题标题】:module resolution with angular2 / ASP.NET5 (cannot find angular2/core)angular2 / ASP.NET5 的模块分辨率(找不到 angular2/core)
【发布时间】:2016-11-10 06:21:42
【问题描述】:

我已经开始了一个新的 ASP.NET5/MVC6 项目。

尝试1我的问题是,当我在tsconfig.json 中将moduleResolution 设置为classic 时,我收到如下错误:

找不到模块“angular2/core”

尝试 2 如果我将tsconfig.json 更改为使用node 分辨率,则tsconfig.js 中的排除node_modules 不起作用,this is a bug? 已关闭,尽管它似乎仍然存在成为一个问题,当 studio 2015 遍历 node_modules 文件夹(包括整个树中的每个 .d.ts)时,会遇到多个错误。有数百个错误,主要在rxjs

尝试 3 如果我完全删除 tsconfig.json,我可以执行应用程序并编译文件,但可惜的是,浏览器中出现此错误。

错误:(SystemJS) 要求未定义

我不禁认为 Visual Studio 中的 angular2 / typescript 支持一团糟,我应该回到 angular 1 和 MVC5。作为记录,我使用的是 typescript 2.0.6,我的 Visual Studio 完全是最新的。

是否有 package.jsontsconfig.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.";
    }
}

【问题讨论】:

    标签: angular typescript


    【解决方案1】:

    注意:确保 es6-shim.d.ts 已安装在 wwwroot 目录中。 typescript 遍历的很多node_modules 文件,如果没有es6-shim.d.ts,就无法编译

    我有一个集成 angular2(2.1.0) 和 ASP.NET 核心的示例,我认为 ng2 的包依赖项也适用于 ASP.NET5。

    package.json

    systemjs.config.js

    希望对你有帮助!

    【讨论】:

    • 谢谢,我已经更新了 .net 核心,并启动了您的大部分应用程序,这需要一些时间才能完成,但它可能会有所帮助。在此期间,我将问题留待一些更直接的答案。
    • 嗨,想知道 es6-shim.d.ts 扮演什么角色。 es6-shim 似乎是让这一切挂在一起所需要的。我在整个 node_modules 目录中的 .d.ts 文件中遇到许多错误,直到 es6-shim.d.ts 被放置在 wwwroot 的某个位置。 tsconfig.json 以 es5 为目标,那么为什么需要 shim?
    • HI,Jim,es6-shim 是为了 es6 功能的兼容性。这里有一些参考。 stackoverflow.com/a/35642381/7045253
    猜你喜欢
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2016-06-14
    • 1970-01-01
    • 2016-04-14
    • 1970-01-01
    • 2016-06-12
    • 1970-01-01
    相关资源
    最近更新 更多