Search code examples
javascriptnode.jsmongoosewebstorm

Unresolved variable Schema when using WebStorm


I am using WebStorm and I have enabled Node Modules in which I have JavaScript Standard Style ( https://standardjs.com ) and it works fine. It underlines when I have ';' or anything like this (basically not following the standard ). When I use mongoose ( const mongoose = require('mongoose') you most probably are familiar with it) and I decide to create model and make the following code

let userSchema = mongoose.Schema({
  username: {type: mongoose.Schema.Types.String, required: true},
  profilePicture: {type: mongoose.Schema.Types.String, required: false},
})

There are more fields but the code is repeating. WebStorm gives me hints about what is in mongoose, Schema and Types, but it underlines them and gives the following

Unresolved variable Schema

and after that

Unresolved variable Types

Here is how it looks enter image description here

It should not give me any errors while compiling but it is quite annoying when trying to follow the standard because I get lots of errors about stuff like "expected 6 spaces found 8" and I check every error and see stuff like this. Does anyone know how to fix it?

EDIT: Managed to fix "Unresolved Variable Schema" by disabling Node Modules coding assistance ( Settings -> Language & Frameworks -> Node.js and NPM) ,but now things like required are Unresolved. Here is a picture enter image description here

Is there a way to have my Node.js hints and also WebStorm understanding mongoose and other objects and their properties?

Btw - This TODO you are seeing - is because WebStorm gives me hints about ObjectID being with capital D, while in other places it is with lower D. This shit crazy.


Solution

  • Not sure if this is relevant for anyone at this point but to solve these mongoose related unresolved variable squigglies in WebStorm you need to go to

    File > Settings...

    enter image description here

    Under Languages & Frameworks, you'll need to select the JavaScript (not Node.js and NPM) category.

    Under that category select Libraries.

    enter image description here

    If you have not downloaded any additional libraries to be used, you'll probably see a list similar to something like this:

    enter image description here

    On the right of the list select the Download... button.

    enter image description here

    A window with a list of libraries will pop up, scroll down until you find mongoose, select it and hit the Download and Install button.

    enter image description here

    After that, your list of libraries will probably look something like this:

    enter image description here

    Webstorm should now be able to understand mongoose related types and variables etc, and should also provide auto-complete options for those as well.