3

I have a userscript that loads jQuery using the @require directive in the metadata block:

// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js

I guess WebStorm doesn't "know" about userscripts, so it has no idea that that, say, $ is a function that will already be defined by the time I reference it in my userscript.

Can I make WebStorm believe that my file effectively has the contents of jquery.min.js inlined at the top of the file, so that it'll stop giving me warnings about $ being undefined? e.g. can I maybe place a local copy of jquery.min.js in a local folder somewhere and tell WebStorm that it can assume all declarations made in that file?

senshin
  • 10,022
  • 7
  • 46
  • 59

1 Answers1

4

Thanks to hobbs for his comment - JetBrains has a documentation page for Configuring JavaScript Libraries.

What I did was:

  1. Download the development version of jQuery 2.1.3 (the "official" JetBrains version of jQuery is 2.0.0).
  2. Go to Settings > Languages & Frameworks > JavaScript > Libraries.
  3. Click Add. In the menu that pops up:
    1. Name it something.
    2. Add (green plus button) the downloaded jquery-2.1.3.js file.
    3. Set Type to Debug.

And now WebStorm believes that my userscript loads jQuery. Hooray!

Community
  • 1
  • 1
senshin
  • 10,022
  • 7
  • 46
  • 59
  • 1. `Settings` > `Languages & Frameworks` > `JavaScript` > `Libraries` 2. Click `Download` 3. Change `Official libraries` to `TypeScript community stubs` 4. Select `jquery` & click `Download and Install` [Adding dependencies in WebStorm](https://stackoverflow.com/questions/13997468/how-do-i-use-webstorm-for-chrome-extension-development) – belgacea Jul 30 '17 at 12:38