【问题标题】:'jQuery is not defined' on upgrading from Durandal 1.2 to 2.0从 Durandal 1.2 升级到 2.0 时出现“未定义 jQuery”
【发布时间】:2013-11-09 01:28:35
【问题描述】:

我已经玩了好几个小时了,这让我发疯了。 chrome 的网络选项卡甚至没有显示 jquery 正在加载,但它在 bundleconfig 中的位置与以前完全相同,并且它两侧的脚本(包括 jquery-ui)都可以正常加载。

我不知道如何调试它 - 它只是不想工作!

bundleconfig 的相关部分:

    bundles.Add(New ScriptBundle("~/scripts/vendor") _
                .Include("~/scripts/jquery-{version}.min.js") _
                .Include("~/scripts/jquery-ui-{version}.min.js") _
                .Include("~/scripts/bootstrap.min.js") _
                .Include("~/scripts/fancytree/jquery.fancytree.js") _

main.js 顶部:

requirejs.config({
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions'
    }
});

define('jquery', function () { return jQuery; });
define('knockout', ko);

define(['durandal/system', 'durandal/app', 'durandal/viewLocator'], function (system, app, viewLocator) {

main.js 中的那一行:

define('jquery', function () { return jQuery; });

在控制台中创建一个错误:“Uncaught ReferenceError: jQuery is not defined”,我猜这是因为尚未加载 jquery 脚本。

【问题讨论】:

  • 我今天也遇到了这个问题:stackoverflow.com/questions/18423253/… 我不知道这是否相关,但我的临时解决方案是在调试模式与发布模式下运行,以防止所有内容被捆绑/缩小。跨度>
  • 仍然不确定问题出在哪里,但是从 bundleconfig 中的两个 jquery 行中删除“.min”会使非缩小的 jquery 文件加载正常。 bootstrap.min.js 仍然可以正常加载,所以我真的不确定发生了什么!
  • 以防万一..您是否在使用 require.js 调用 main.js 之前加载包???
  • 呃……可能吗?我的 index.vbhtml 文件在底部有这个:@Scripts.Render("~/scripts/vendor")

标签: jquery durandal


【解决方案1】:

请注意,在 DEBUG 模式下运行时,BundleConfig 默认会忽略文件名中包含 .min 的 javascript 文件。

我总是在 RegisterBundles() 函数中首先包含这一行:

bundles.IgnoreList.Clear();

然后您可以将自己的条目添加到忽略列表中,如下所示:

bundles.IgnoreList.Ignore("*.intellisense.js");
bundles.IgnoreList.Ignore("*-vsdoc.js");
bundles.IgnoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);

【讨论】:

  • 感谢 Brett 的输入,但事实并非如此。我的 bundleconfig 已经完成了所有这些。这在将 Durandal 从 1.2 升级到 2.0 之前运行良好。不过,其他一些脚本也得到了更新(我从控制台执行了“更新包”命令并升级了所有内容),所以我不知道故障是在哪里引入的。事实仍然是在同一目录中有 .min 和普通 js 文件,因此即使指定了“.min”,bundleconfig 文件也应该加载普通文件。它不会这样做,只有当我从定义中删除“.min”时才有效。
【解决方案2】:

尝试将此代码放在 BundleConfig 文件的开头:

BundleTable.EnableOptimizations = false;
bundles.IgnoreList.Clear();

【讨论】:

  • 谢谢塔玛拉。这与 Brett 发布的内容相似,没有任何区别。
猜你喜欢
  • 1970-01-01
  • 2011-06-18
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 1970-01-01
  • 2023-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多