9

I am trying to use Bootstrap and JQuery in my new ASP.Net Core application. But I encounter the error "Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3" when I try to run the application.

I have used bower to add Bootstrap to my application, and have added version 3.3.6 of Bootstrap which automatically adds JQuery 2.2.4. The problem is that it seems that version 2.2.4 of JQuery is actually versioned at 3.0.0-rc1, which causes Bootstrap validation to fail as it will only accept versions of JQuery from version 1.9.1 but less than version 3?

How can I resolve this conflict? How is it that Bootstrap comes packaged with an incompatible version of JQuery?

Here you can see my files in my solution, showing the Bootstrap and JQuery versions: as you can see there are no other versions of JQuery installed either.

Here is a snippet of my Html markup

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
</head>
<body>
    <h1>HELLOOOO!</h1>
    <script type="text/javascript" src="~/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
</body>

</html>

Which results in Chrome reporting "Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3"

Any help would be greatly appreciated!

tainted.eye
  • 101
  • 1
  • 5
  • What does your bower file look like? – Phil Jun 02 '16 at 06:46
  • { "name": "ASP.NET", "private": true, "dependencies": { "bootstrap": "^3.3.6" } } – tainted.eye Jun 02 '16 at 06:49
  • And what version of Bower are you using? Mine (1.7.9) installed jQuery 2.2.4. Perhaps try deleting your `lib` directory and re-running `bower install` – Phil Jun 02 '16 at 06:54
  • I was using Visual Studios in-built bower package manager, but I now tried the proper bower package manager and used the console to install the same package. It works 100% using the proper manager. It seems there is a problem with the Visual Studio one! Thanks very much for the help :) – tainted.eye Jun 02 '16 at 08:08
  • @Phil - would you like to add an official comment so that I can mark you correct and grant you some sweet karma? – tainted.eye Jun 02 '16 at 08:09

3 Answers3

25

We found that the root of the problem is git.exe from C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git which is not a real Git but some sort of a wrapper.

With it, bower tries to install correct versions, but if you look into the bower cache you can see that actual downloaded files don't match.

Example:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External>

bower install jquery#2.2.4
bower jquery#2.2.4          not-cached https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             resolve https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4            checkout 2.2.4
bower jquery#2.2.4            resolved https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             install jquery#2.2.4

jquery#2.2.4 bower_components\jquery

Check the contents of "%USERPROFILE%\AppData\Local\bower\cache\packages\35300e45e44dbc6f186ed069533ef0af\2.2.4\dist\jquery.js":

/*eslint-disable no-unused-vars*/
/*!
 * jQuery JavaScript Library v3.1.0

Solution:

  1. Install Git for Windows
  2. Delete %USERPROFILE%\AppData\Local\bower
  3. Restart Visual Studio
  4. Delete wwwroot/lib and Restore bower packages

Update: You might also need to adjust VS external web tools settings

amartynov
  • 4,125
  • 2
  • 31
  • 35
  • 6
    In my case this didn't quite fix the issue... I also had to modify the path that VS searched for Git. Before step 4, I went to Tools->Options->Projects and Solutions->External Web Tools and replaced "$(VSINSTALLDIR)\Web\External\git" with "C:\program files\git\bin". – raistlin0788 Sep 12 '16 at 15:48
  • @raistlin0788 Thanks for the hint. However the global PATH (to which Git for Windows is added by default) should take precedence over "External/git". See screenshots at https://blogs.msdn.microsoft.com/webdev/2015/03/19/customize-external-web-tools-in-visual-studio-2015/ – amartynov Feb 09 '17 at 09:20
  • I am really losing faith in the microsoft dev tools. – EthR Feb 09 '17 at 20:45
1

As pointed out by Phil, this is caused by Visual Studio's built in Bower support. When using this, it seems to download a different version of JQuery.

To fix this, I just used the proper Bower client and installed my packages through the console.

tainted.eye
  • 101
  • 1
  • 5
0

Delete the Lib forder on the wwwroot and run bower install, ensure that in your bower.json file you have the version of jquery that you want.

Frawel
  • 3,574
  • 1
  • 17
  • 13