簡體   English   中英

ASP.NET 在 jQuery 捆綁包上接收 NullReferenceException

[英]ASP.NET Receiving NullReferenceException on jQuery Bundle

問題:我在 @Scripts.Render("~bundles/jquery") 上收到NullReferenceException

我昨晚部署並進行了測試,一切都很好。 今天早上醒來,決定檢查網站並注意到它。 我也沒有碰過任何奇怪的東西。

這不會在當地發生!!!!!!

代碼片段

@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
<script src="https://cdn.jsdelivr.net/npm/vue"></script>

捆綁配置

public static void RegisterBundles(BundleCollection bundles)
    {
        bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                    "~/Scripts/jquery-{version}.js"));

        bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.validate*"));

        // Use the development version of Modernizr to develop with and learn from. Then, when you're
        // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
        bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                    "~/Scripts/modernizr-*"));

        bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                  "~/Scripts/bootstrap.js"));

        bundles.Add(new StyleBundle("~/Content/css").Include(
                  "~/Content/bootstrap.css",
                  "~/Content/site.css"));
    }

我嘗試過的事情:

  • 重建 + 完全部署
  • 重置/回收
  • 重命名帶有硬編碼版本的捆綁包有什么建議嗎? 這與 Minify 有關嗎?

編輯#1

編輯#2我可以確認我在訪問https://example.com/Scripts/jquery-3.4.1.min.js時看到正在加載 JS 文件

編輯#3我嘗試替換所有捆綁引用以從腳本和內容文件夾中提取,現在我收到一些奇怪的 jQuery 錯誤...注意,我更喜歡使用捆綁。

<link href="~/Content/Site.css" rel="stylesheet" />
<link href="~/Content/bootstrap-theme.min.css" rel="stylesheet" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" />
<script src="~/Scripts/modernizr-2.8.3.js"></script>
<script src="~/Scripts/jquery-3.4.1.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>

在此處輸入圖像描述

編輯#4我有一個 TEMP 解決方案,它使用最新的 CDN 進行引導,但我更喜歡使用標准捆綁。

嘗試拼出 jquery 版本而不是 {version}

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery.1.6.22.js"));

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                "~/Scripts/jquery.validate*"));

    // Use the development version of Modernizr to develop with and learn from. Then, when you're
    // ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
    bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                "~/Scripts/modernizr-*"));

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
              "~/Scripts/bootstrap.js"));

    bundles.Add(new StyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.css",
              "~/Content/site.css"));
}

並確保 js 文件存在於編譯的

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM