41

I have tried this:

JQuery intellisense in Visual Studio Code

and this:

http://shrekshao.github.io/2016/06/20/vscode-01/

But it does nothing, VS Code just won't add jquery intellisense, I've been trying to solve this for hours but it just won't work

SaraFlower
  • 755
  • 1
  • 8
  • 15

5 Answers5

100

Most of the blog postings are now outdated, as we finally have automatic type acquisition with version 1.8+ - you no longer need to install the typings yourself.

I recommend reading the official documentation, its always up to date: https://code.visualstudio.com/docs/languages/javascript

If you use npm and have a package.json in your project and jQuery is listed there, it should already work.

If you do not use npm, you can create the file jsconfig.json in the project root with the following content and you are good to go:

{
    "typeAcquisition": {
        "include": [
            "jquery"
        ]
    }
}
Danny Bullis
  • 3,043
  • 2
  • 29
  • 35
kwood
  • 9,854
  • 2
  • 28
  • 32
  • 1
    hi kwood, can i add jquery intellisense to vs code without a project? i edit many arbitrary js files in different environments. – Ted Fitzpatrick Dec 01 '17 at 16:51
  • This worked for me on one machine but not on another. (Same repo on both.) Any insight into what might prevent jquery support when it's manually included like this? – snarf Dec 24 '17 at 18:56
  • @anaval : Just tested, it works for `AngularJS` too: `"typeAcquisition": { "include": [ "jquery", "angular" ] }` – Antonio Ooi Aug 29 '20 at 09:22
  • I had to delete the jsconfig.json file and use the approach below with npm. I also had to restart vs code in order to get it to recognize that I had installed node. I have to say, this a ridiculous pain in the ass for both VS Code and full VS 2022. Not happy right now. – tnk479 Sep 08 '22 at 14:06
19

Type this command in your project root :

npm i --save @types/jquery
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Wong Jia Hau
  • 2,639
  • 2
  • 18
  • 30
  • i tried installing it globally. It got added to the global modules but did not take effect in vs code. Any ideas ? (and yes i have tried closing and opening vs code after i installed it globally) – eran otzap May 13 '18 at 20:04
  • 1
    @eranotzap I believe this command has to be run in a project and not globally. When you install it globally it does not work. – Douwe de Haan Oct 11 '19 at 12:24
7

I had the same problem and google brought me here. I added the type jsconfig.json and "typeAcquisition" and still nothing.

Turns out you have to have node and npm installed. Even if you are not using them for package management and are importing jquery from a CDN.

From the Docs

Many popular libraries ship with typings files so you get IntelliSense for them automatically. For libraries that do not include typings, VS Code's Automatic Type Acquisition will automatically install community maintained typings file for

Automatic type acquisition requires npmjs, the Node.js package manager, which is included with the Node.js runtime. In this image you can see IntelliSense, including the method signature, parameter info, and the method's documentation for the popular lodash library.

https://code.visualstudio.com/docs/nodejs/working-with-javascript

So vs code uses npm for auto type acquisition.

May be super basic, but it solved my problem so I hope it helps someone else too.

I also used the configuration in jsconfig.json as described by kwood. Not sure I needed to specify it manually after installin npm but it is working so i'm not asking questions

Community
  • 1
  • 1
Ben
  • 225
  • 3
  • 11
3

I thought that the major reason is Vscode does not parse the Jquery.js file because original jquery file is minified, which leads to vscode stop tokenization of the file. To solve this, open the jquery.js file, right click and select format. The tokenization process will complete.

user8805240
  • 41
  • 1
  • 3
3

What helped me was using the non-minified version of jQuery, and then use

/// <reference path="./jquery-3.4.1.js" />

in the beginning of my JS file.

(I'm coding client-side i.e. ES5 JavaScript that is added to the page directly with the <script> tag.)

mkkekkonen
  • 1,704
  • 2
  • 18
  • 35