Back

Technologies:

javascriptjavascript
jqueryjquery
avatar
Tolerim
21 hours ago

An unhandled exception occurred in Bootstrap.js for the ASP.NET web application due to Bootstrap's JavaScript requiring jQuery.

I am currently working on a project for an ASP.NET Web Application and encountering JavaScript errors associated with jQuery and Bootstrap. The errors present as two separate issues: "JavaScript critical error in https://localhost:44383/Scripts/jquery-3.4.1.js\n\nSCRIPT1010: Expected identifier"

"Unhandled exception in https://localhost:44383/Scripts/bootstrap.js 0x800a139e - JavaScript runtime error: Bootstrap's JavaScript requires jQuery."

Despite having the correct order of JavaScript files in my HTML or layout files (e.g., _Layout.cshtml) and having jQuery loaded before Bootstrap, the errors persist. More specifically, the first error, which concerns jQuery, reports that an expected identifier was missing in the jquery-3.4.1.js file. In contrast, the second error, which pertains to Bootstrap, throws an unhandled exception in the bootstrap.js file and requires jQuery to function. Here's an example of the correct code:
`@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)`
Likewise, my bundle configuration files (e.g., BundleConfig.cs) are correct:
`public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                        "~/Scripts/jquery-3.4.1.js"));

            bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
                        "~/Scripts/modernizr-2.8.3.js"));

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

            bundles.Add(new StyleBundle("~/Content/css").Include(
                      "~/Content/bootstrap.css",
                      "~/Content/site.css"));`
Answers(1)
avatar
Tolerim
21 hours ago
Verified Answer
The errors you are encountering are related to jQuery and Bootstrap. The first error "Expected identifier" is occurring in the jquery-3.4.1.js file. The second error "Bootstrap's JavaScript requires jQuery" is occurring in the bootstrap.js file. Your project seems correctly configured. However, the issue might be caused by using the wrong version of jQuery or by missing the include for jQuery. Firstly, verify that the correct version of jQuery has been installed and included in BundleConfig.cs. Secondly, check that jQuery is being loaded before Bootstrap. To help you further, do review the version of jQuery and Bootstrap on both your HTML files and BundleConfig.cs.
;