node.js - Angular2 Visual Studio 2017 MVC : Uncaught TypeError: System. 配置不是一个函数

标签 node.js asp.net-mvc angular visual-studio systemjs

我正在通过 Visual Studio 2017 ASP.NET MVC 构建 Angular2 Web 应用程序

我所做的所有基本配置。

但是当我尝试构建应用程序时,它会抛出错误。

错误:

enter image description here

令我惊讶的是,有时应用程序成功运行,但有时会抛出此错误。

已关注 this link进行快速设置

package.json、tsconfig.json 和 systemjs.config.js 复制自quickstart

_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
<script src="/node_modules/core-js/client/shim.min.js"></script>
<script src="/node_modules/zone.js/dist/zone.js"></script>
<script src="/node_modules/systemjs/dist/system.src.js"></script>
<script src="/system.config.js"></script>
<script>
    System.import('app').catch(function (err) { console.error(err); });
</script>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")

</head>
<body>
<div class="container body-content">
    @RenderBody()
    <hr />
    <footer>
        <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
    </footer>
</div>

@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>

Index.cshtml

@{
ViewBag.Title = "Home Page";
}

<app-root>Loading...</app-root>

最佳答案

您需要使用 Url.Content() 解析脚本的路径:

<script src="@Url.Content("~/node_modules/core-js/client/shim.min.js")"></script>
<script src="@Url.Content("~/node_modules/zone.js/dist/zone.js")"></script>
<script src="@Url.Content("~/node_modules/systemjs/dist/system.src.js")"></script>
<script src="@Url.Content("~/system.config.js")"></script>

这样,如果您的路线更改为/controller/action/something,您可以确保它始终解析为应用程序路径的根目录,而不是某些 fubfolder。

关于node.js - Angular2 Visual Studio 2017 MVC : Uncaught TypeError: System. 配置不是一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47479713/

相关文章:

node.js - 如何存储 Node.js CLI 工具的特定选项?

angular - Angular 6。 httpClient中错误处理的正确方法

angular - 将参数传递给 withLatestFrom 函数

javascript - 如何在 perl 的 JE 引擎中实现 "JS' s require"函数?

javascript - 为什么这个 reduce 方法不给我对象?

node.js - Sequelize Unknown column '*.createdAt' in 'field list'

asp.net-mvc - 在表单提交时传递整个模型

c# - 如何屏蔽特定请求的敏感数据 (NLog)

javascript - 如何将 MVC 模型数据与 Angular JS 模型链接起来

html - 如何减小Ionic2中文本输入的大小并在右侧对齐标签