Reputation: 7800
I just installed WebStorm. I'm working on a small Node.js app.
I've attached the Node.js source code, and when I click on the Node.js settings, I can see that it can recognize my various node modules, etc.
I'm having two issues:
exports
, require
).require('winston')
, it tells me that it has no code insight. (Is there a way I can add the source code?)Upvotes: 30
Views: 10995
Reputation: 2271
Working with WebStorm and Node.js these two code-segments regularly gave me "false positive" warnings:
FALSE POSITIVE WARNING CASE 1:
module.exports = ...
That gave me the warning "Element is not exported". I was able to get rid of the warning caused by that by putting this above the "module.exports = ..."
/** @namespace module.exports **/
FALSE POSITIVE WARNING CASE 2:
let something = global.something ;
That gave me the warning "Unresolved variable or type global". I was able to eliminate the warning caused by that by putting this above it:
/** @namespace global **/
I now put the following on top of my .js- or .mjs-files to be executed by Node.js, and get rid of warnings referring to these variables or properties:
/** @namespace global **/
/** @namespace console **/
/** @namespace process **/
/** @namespace Buffer **/
/** @namespace process.stdin **/
/** @namespace module.exports **/
I am using WebStorm 2022.2.3
Upvotes: 0
Reputation: 15265
As I've answered on the WebStorm says console is an unresolved variable question, to solve these problems on the new Webstorm versions, you need to enable the Coding assistance for Node.js.
To do this, go on the Settings
> Languages & Frameworks
> Node.js and NPM
and click on the Coding assistance for Node.js
option, and then click OK to save:
This will all Node.js unresolved variables and functions.
On the new Webstorm versions, just going above error and clicking in More Actions...
(or ALT+ENTER) and selecting
Enable Node.js coding assistance will solve this.
Upvotes: 0
Reputation: 9406
I use WebStorm 2020 and I had everything enabled but WebStill though showed that module.exports
is unknown function. Then I turned off NodeJS.core library and NodeJS code assistance, applied and then turned them on again. And suddenly it started to work.
Upvotes: 0
Reputation: 4348
For WebStorm 7 thru 10 (on OSX)…
WebStorm → Preferences → Languages & Frameworks → Javascript → Libraries
Select "Node.js Globals" and "Node.js vXXX Core Modules".
Upvotes: 31
Reputation: 151855
For 2018 and later versions of WebStorm:
In Settings -> Languages & Frameworks -> Node.js and NPM, check Coding assistance for Node.js:
In older Webstorm versions, this was called Enable Node.js Core library.
If you still see unrecognized Node symbols even with that option enabled, unckeck it, restart WebStorm, then right click on the warning and choose Enable Node.js coding assistance or just check the option again. Watch for WebStorm to show it's Indexing files. (Just had this happen today - looks like a WebStorm bug, and what I just wrote fixed the situation.)
Upvotes: 59
Reputation: 732
Updating to Webstorm 8 or higher will fix your require methods problem. As posted earlier by checking if Settings > JavaScript > Libraries > Node.js are all checked will fix your problem
Upvotes: -1