[solved] No longer getting require() or import suggestions on Opt-Enter (context menu)

It used to be that if I had code like this: someOtherModule.functionFoo()

but I had forgotten to require or import the module,

then the Opt-Enter menu would auto-suggest to me to 'require' or to 'import' someOtherModule. (I think it found it by looking for functionFoo exports.)

If chosen, it would put a new 'require' or 'import' line near the top of the file. Nice!

 

Somehow this functionality has been lost from my WebStorm. Any idea how I can get it back?

 

I care most when `someOtherModule` is a module defined in my project, and not a node_module, but of course support for both would be best.

 

My environment:

I recently upgraded NodeJS from 4.2.2 to 8.1.2 (using nvm; multiple Node versions installed). It is possible that this is what triggered the issue.

I have just installed the latest version of WebStorm. (Before that, I could not Enable "Node.js Core library" for Node v8.1.2.)

0
2 comments

Works for me in 2017.2

>It is possible that this is what triggered the issue.

No, unlikely

Do you have JavaScript | Node.js | Missing require() statement inspection enabled in Preferences | Editor | Inspections?

0
Avatar
Permanently deleted user

JavaScript | Node.js | Missing require() statement inspection enabled

 

Thank you Elena, that was exactly it!

I had disabled that inspection because it was bothering me in some of the front-end code.

I will try to do something with scopes in future, so I can use that inspection only on the back-end files.

It is nice to see that since the upgrade WebStorm is now adding the new require line with a `const` instead of a `var` :)

0

Please sign in to leave a comment.