Search code examples
node.jswebstorm

WebStorm incorrectly shows unresolved method in Node.js app


I have installed WebStorm 2019.3 and there is a weird unresolved function warning for a bcryptjs library. The project is Node.js and I did npm install.

There are other dependencies working fine but this particular does not. Any idea?

const bcrypt = require('bcryptjs');
const jwt = require('jsonwebtoken');
const MongoClient = require('mongodb').MongoClient;

MongoClient.connect(uri) // OK, not highlighted
const token = jwt.sign({ // OK, not highlighted

if (bcrypt.compareSync(password, user.password)) { // KO, highlighted as unresolved

Solution

  • Please try un-excluding node_modules\bcryptjs\dist folder: right-click it, choose Mark directory As/Not Excluded; re-open the project.

    I'd also suggest installing bcryptjs typings for better coding assistance: put cursor on 'bcryptjs' in require('bcryptjs'), hit Alt+Enter, choose Install Typescript definitions for better type informaion. See https://www.jetbrains.com/help/webstorm/2019.3/configuring-javascript-libraries.html#ws_jsconfigure_libraries_ts_definition_files

    enter image description here