How to stop NodeJS require() being flagged as "unresolved"

I've recently done the WS upgrade to 2018.3 - unfortunately somehow during the course of that some setting's got messed up. So now when I load my NodeJS JS code I'm getting the in-built code inspector, (note, not ESLint, JSHint, etc), complaining that "Unresolved function or method require()".  I've checked online and all the articles say to make sure that "Node.js Core" is enabled in Preferences->Languages & Frameworks->JavaScript->Libraries. I've checked and it is.

So is there some other step I need to do to make sure that WS recognises require() as being known (because it's part of NodeJS). It's also complaining about "module" too as being an "Unresolved variable or type module".

 

Thanks.

10
29 comments

Must be https://youtrack.jetbrains.com/issue/WEB-35836. Please disable Node.js coding assistance in Preferences | Languages & Frameworks | Node.js and NPM, apply and then re-enable it to get libraries downloaded - does it help?

19

(Sorry for delay - was on vacation)

Thanks @Elena - that does indeed cure my problem!

:-D

2
Avatar
Permanently deleted user

I have this same problem - applying the settings described by @Elena doesn't work for me.  Running WebStorm 2018.3.2.

0
Avatar
Permanently deleted user

Confirming that this issue exists in Webstorm 2018.3.3. Steps disable/enable Node.js coding assistance do not work for me.

0

Please see my comment above

1
Avatar
Permanently deleted user

Can JetBrains just reproduce it?  Looks like it's happening for everyone.  I can't supply any files since it's against my company's policy.

0

If we could reproduce it, I won't ask you for steps, logs, etc. And no, it doesn't happen to everyone, it works for almost all users

1

I also had this problem on Ubuntu. I had installed Node using apt install node and require was being recognized. Then I installed/updated Node using the npm package 'n', after which require stopped being recognized. I tried the steps above and they didn't work for me, even though I had the new Node installed by 'n' selected. 'require' started being recognized again after I removed the Node installed with n.

 

Also worth noting maybe? I'm using Rubymine (not Webstorm)

Maybe this will help someone. 

0

I have the same problem with a fresh installation of webstorm! 

0

Please make sure to enable Node.js coding assistance in Preferences | Languages & Frameworks | Node.js and NPM; if it doesn't help, try invalidating csches

4
Avatar
Permanently deleted user

The same thing. Everything is enabled, but codding assistance just doesn't work in WS. Doesn't matter for which project. Was forced to open it in PhpStorm. Here everything works fine.

0

This feature works exactly the same in WS and PhpStorm (same plugins involved). Something must be broken in your WS configuration/installation

0
Avatar
Permanently deleted user

Invalidating the cache worked for me. Go to `File > Invalidate Caches / Restart...` then select `Invalidate and Restart`

1

I'm using Webstorm 2019.3.3 and 

I have:

* Enabled Coding assistance for Node.js:

* Invalidated the cache and restarted WebStorm

But I still have the same error ESLINT: require is not defined (no-undef).

The error is on all the Node.js functions.

 

1

The error comes from ESLint, not from the IDE. You have to either add "require" to ESLint "globals": {} or set the environment accordingly (see https://stackoverflow.com/questions/58530202/how-to-fix-eslint-require-is-not-defined-when-it-is-used-in-just-one-file)

0

Ok thank you @Elena Pogorelova I've specified the node enviroment in the file .eslintrc.json:

{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"extends": ["eslint:recommended", "google"],
"rules": {
"semi": "error",
"no-console": 0
},
"env": {
"node": true
}
}
0

Hello!

I have tried everything from invalidating caches to enabling and disabling Nodejs support to reinstalling Webstorm... Unfortunately I still have the same problem.
Here's my log file: https://s3-ap-southeast-2.amazonaws.com/cdn.rapidaim.be/idea.log

 

Thank you and I will be looking forward to your comments.

0

Hello, that bug where we have to:

disable and re-enable File->Settings->Node.js and NPM->Coding Assistance for Node.js 

for require and the core modules to be recognized still exist after more than two years, is nobody working on fixing that? The priority should have gone up by now, it's been two years...

Regards

0

Hi, I have same problem in WebStorm 2020.3(on macOS Catalina).

I tried disable and re-enable `Preferences -> Languages & Frameworks -> Node.js and NPM -> Coding Assistance for Node.js`, unfortunately still same problem.

But, I may have found a workaround.

I use nodenv. So, I changed the "Node interpreter" from a reference to an entity.

e.g. `~/.anyenv/envs/nodenv/shims/node` to `~/.anyenv/envs/nodenv/versions/15.3.0/bin/node`

And, disabled and re-enabled "Coding Assistance for Node.js" checkbox, then, IDE looks like resolved `require()` and references.

I don't know if it is reproducible just now. (Still not retry.)

1

I had the same issue. Disabling and reenabling Coding Assistance for Node.js did not work for me either. What worked was adding @types/node under javascript libraries. 

Putting this here if anyone is facing the same issue in 2025.

3
Avatar
Permanently deleted user

The workaround that has worked for me is selecting an older version of Node. Not saying the issue is node version dependent, but after trial/error this is what I have found "fixed it" for me. I have another project open in a different window of WebStorm that has node v12.19.0 selected, and that project is not experiencing problems, but that project is using a different JavaScript library, namely the projects node_module/ folder (see second screenshot) whereas the problem project is using the a predefined Node.js Core library (see third screenshot). Not sure if this has anything to do with anything, just pointing out the differences I notice become control and test group.

First:

 

Second

 

Third:

0
Avatar
Permanently deleted user

Ah, update to the post I submitted just a few minutes ago. I manually added a Node library, namely the "node_modules/" folder of my v12.19.0 installation (to match the version of node selected in "Node & NPM" settings, see first screenshot), and now my project is fixed for good, regardless of the Node version I select in "Node & NPM" settings, and even with the "Coding assistance for Node.js" unchecked/unselected (see second screenshot)!!! Hope this helps someone,

First:

 

Second:

1

>Not saying the issue is node version dependent

It can indeed be Node.js version dependent, as the APIs used for retrieving the modules are often version-specific. Old IDE versions can't be expected to work with the recent Node.js releases

0

In regards to this 'unresolved function' inspection result, if my program works when I do something related to the function, then that means that the function is being used. I don't understand why it gets marked as being 'unresolved' in the first place. 

0

Abbas Egbeyemi nice fix. Worked for me as well. Thanks for taking the time to share :)

0

For those who use volta as node package manager, I fixed the "unresolved" require by setting
Preferences | Languages & Frameworks | Node.js and NPM the path to
Node interpreter: ~\AppData\Local\Volta\tools\image\node\16.13.1\node.exe
Package manager: ~\AppData\Local\Volta\tools\image\node\16.13.1\node_modules\npm

Worked for me afterwards.

1

Dec 2022, 2 days away from it being 2023 and this issue is still happening !

 

Thanks for the solutions discussed here they still fix the problem

0

Please sign in to leave a comment.