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.
Please sign in to leave a comment.
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?
@Elena That indeed solves my problem https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001788619-WebStorm-unable-to-recognize-Nodejs-APIs
(Sorry for delay - was on vacation)
Thanks @Elena - that does indeed cure my problem!
:-D
I have this same problem - applying the settings described by @Elena doesn't work for me. Running WebStorm 2018.3.2.
Please perform the steps from https://intellij-support.jetbrains.com/hc/en-us/community/posts/360001718840/comments/360000255319 and provide your idea.log (https://intellij-support.jetbrains.com/hc/en-usa/articles/207241085-Locating-IDE-log-files)
Note: don't paste log here, upload it to file server and provide a link
Confirming that this issue exists in Webstorm 2018.3.3. Steps disable/enable Node.js coding assistance do not work for me.
Please see my comment above
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.
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
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.
I have the same problem with a fresh installation of webstorm!
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
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.
This feature works exactly the same in WS and PhpStorm (same plugins involved). Something must be broken in your WS configuration/installation
Invalidating the cache worked for me. Go to `File > Invalidate Caches / Restart...` then select `Invalidate and Restart`
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.
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)Ok thank you @Elena Pogorelova I've specified the node enviroment in the file .eslintrc.json:
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.
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
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.)
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.
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:
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:
>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
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.
Abbas Egbeyemi nice fix. Worked for me as well. Thanks for taking the time to share :)
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.
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