最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught ReferenceError: moment is not defined - Stack Overflow

programmeradmin2浏览0评论

I'm trying to use moment.js with moment-jalaali.js plugin.

moment-jalaali is a plugin for moment js that adds support for jalaali (solar) calendar.

Obviously in a web page one should first include moment.js then moment-jalaali.js in order to make it work.

I'm doing it and it's giving me the Uncaught ReferenceError: moment is not defined. Google chrome says it's caused at line 31 at moment-jalaali.js :

require.modules = {
    moment: { exports: moment } // here the error happens
};

I'm using these js libraries in nopmerce (ASP.NET application) and I'm including them like the following in admin area layout:

Html.AppendScriptParts(string.Format("~/Scripts/kendo/{0}/kendo.web.min.js", kendoVersion));
Html.AppendScriptParts("~/Scripts/adminmon.js");
Html.AppendScriptParts("~/Scripts/jquery-migrate-1.2.1.min.js");
Html.AppendScriptParts("~/Scripts/jquery-ui-1.10.3.custom.min.js");
Html.AppendScriptParts("~/Scripts/jquery.validate.unobtrusive.min.js");
Html.AppendScriptParts("~/Scripts/jquery.validate.min.js");
Html.AppendScriptParts("~/Scripts/jquery-1.10.2.min.js");
Html.AppendScriptParts("~/Scripts/moment.js");
Html.AppendScriptParts("~/Scripts/moment-jalaali.js");

Even if I include them before everything else, it still does not work.

Surprisingly if i make a simple html page like the following they work perfectly.

<html>
<head>
    <script src="moment.js"></script>
    <script src="moment-jalaali.js"></script>
</head>
<body>
</body>
</html>

What is causing the error and how can I fix it?

EDIT

If I include moment-jalaali.js in the View itself but still include moment.js in the Layout it works fine. However it's not a proper solution so I'm still looking for a better way.

发布评论

评论列表(0)

  1. 暂无评论