【问题标题】:Angular Issue - Cannot GET /角度问题 - 无法获取 /
【发布时间】:2019-05-18 19:35:18
【问题描述】:

我正在 Visual Studio 2017 中运行带有 AngularASP.NET Core 应用程序。不幸的是,每当我运行该项目时,它都会在浏览器中显示以下消息:

Cannot GET /

谷歌搜索了几个小时 (Sample Link),我尝试了以下操作,并在 tsconfig.json 文件中添加:

"lib": [ "es5", "es6", "es2017", "dom" ]

在我的情况下,更早的情况如下:

"lib": [ "es2017" ]

虽然项目搭建成功,但也很少出现如下错误:

Severity    Code    Description Project File    Line    Suppression State
Error   TS2583  (TS) Cannot find name 'Set'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.  ASP.NETCoreWithAngular  C:\Users\Amit's-PC\source\repos\ASP.NETCoreWithAngular\ASP.NETCoreWithAngular\ClientApp\node_modules\@angular\common\src\directives\ng_class.d.ts   48  Active

Severity    Code    Description Project File    Line    Suppression State
Error   TS2583  (TS) Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.  ASP.NETCoreWithAngular  C:\Users\Amit's-PC\source\repos\ASP.NETCoreWithAngular\ASP.NETCoreWithAngular\ClientApp\node_modules\@angular\core\src\change_detection\differs\default_keyvalue_differ.d.ts    24  Active

Severity    Code    Description Project File    Line    Suppression State
Error   TS2585  (TS) 'Promise' only refers to a type, but is being used as a value here. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.  ASP.NETCoreWithAngular  C:\Users\Amit's-PC\source\repos\ASP.NETCoreWithAngular\ASP.NETCoreWithAngular\ClientApp\node_modules\rxjs\Observable.d.ts   58  Active

我在这里错过了什么?任何想法将不胜感激。

【问题讨论】:

    标签: asp.net angular asp.net-core


    【解决方案1】:

    从您收到的错误消息看来,JavaScript 的默认配置很可能是es5 或低于es2015 的任何其他配置。这意味着您正在尝试使用es2015 功能,而您的编译器现在允许您使用。检查您的 IDE 配置并确保您的 JavaScript 配置至少设置为 es2015

    【讨论】:

    • 所以你的意思是即使它在 Visual Studio 2017 中运行,我也应该包括 es5es2015?感谢您的建议,并会尝试@Hugo Noro。
    • 检查 Visual Studio 上的 JavaScript 配置。在将 TypeScript 转换为 JavaScript 时,很可能默认使用 es5。如果是这种情况,则意味着您将无法使用 es2015 或 es2017 的功能
    【解决方案2】:

    根据您的错误,我认为您的应用程序的 MVC 部分存在路由问题。你应该忍受你的默认路由配置正确。

    以下文章在这里提供了一些有用的指导。

    https://knightcodes.com/angular2/2017/01/05/angular-2-routes-with-asp-net-mvc.html

    【讨论】:

      猜你喜欢
      • 2018-03-28
      • 2016-07-27
      • 2019-01-07
      • 1970-01-01
      • 1970-01-01
      • 2018-09-15
      • 1970-01-01
      • 2021-04-03
      • 1970-01-01
      相关资源
      最近更新 更多