43

If you follow JetBrains' Getting Started with Node.js in WebStorm instructions, node-express specific code is highlighted correctly. However if you create your own simple node-express project, e.g. using node-express' Guide, then express specific functions such as app.get() are underlined and marked with the following warning:

Unresolved function or method get()

This happens even if you enable the following libraries under Settings\JavaScript\Libraries:

  • Node.js Globals
  • Node.js v0.10.31 Core Modules
  • express-DefinitelyTyped (which you need to download)

How can I configure WebStorm to resolve node-express functions such as app.get()?

Jonathan Livni
  • 101,334
  • 104
  • 266
  • 359

3 Answers3

93

Instead of express definitelyTyped, use express types in your project:

npm install --save-dev @types/express

Alternatively, for yarn users:

yarn add --dev @types/express
Jorge Gil
  • 4,265
  • 5
  • 38
  • 57
  • @Jonathan, by adding express definitelyTyped is very straightforward for me to fix the warning and everything. The only notable difference at this moment with you is that I'm using IDEA instead of WebStorm. Can we validate if you please tell which versions are you using of ECMAScript, Node.js and express? I'm using ECMAScript 6, Node.js v8.3.0 and express v4.15.4. I have the filling you're on ECMAScript 5.1 :-) – Jorge Gil Oct 06 '17 at 05:14
  • 1
    This worked for me, but i wanted to use it globally and `-g` flag did not work. so I added another answer with a link to a guide that allows to install it globally. – e-shfiyut Aug 30 '18 at 12:06
62

This worked great for me.

TL;DR: you go to Settings/Preferences --> Languages and Frameworks --> JavaScript --> Libraries, click the Download button on the right, then select "express" (or any other library you need) and click Download and Install.

e-shfiyut
  • 3,538
  • 2
  • 30
  • 31
  • I have tried. But after click Download and Install. There's no any response. I wonder if the new version (2019.1) of webStorm has changed. – GoodApple Jul 21 '19 at 08:09
  • maybe you are having some kind of connection issue? This is still working for me (i'm on IDEA, not webStorm, but it is supposed to be the same...) – e-shfiyut Jul 21 '19 at 13:53
  • Thanks. Solved. I finally found out that it (@types/express) was already in the list so there's no response. The problem of lacking of coding assistance and being shown as unresolved symbol solved by installing the required package. const { body, validationResult } = require('express-validator/check'); const { sanitizeBody } = require('express-validator/filter'); – GoodApple Jul 21 '19 at 14:53
1

Enabling express-DefinitelyTyped typescript library for Express project does work for me - app.get() is successfully resolved. Adding typescript stubs is the only possible workaround, as WebStorm can't understand the way express is defined - see https://youtrack.jetbrains.com/issue/WEB-6667#comment=27-470393

If adding typescript stubs doesn't work for you, please try invalidating caches. If this doesn't help, I'd suggest contacting jetbrains support, providing a sample project

lena
  • 90,154
  • 11
  • 145
  • 150
  • 1
    Has it worked for you while following node-express' [Guide](http://expressjs.com/guide.html)? For me adding express-DefinitelyTyped does change the color of `get` from grey to purple in the default theme, however the underline and warning still persist. I tried the cache invalidation, it didn't help. – Jonathan Livni Sep 30 '14 at 13:52
  • I see. the problem is that webstorm can't match parameters of app.get() with the ones specified in express.d.ts (doesn't expect a callback as asecond parameter). You can try turning 'signature mismatch' inspection off to avoid seeing the warnings – lena Sep 30 '14 at 15:11