5

I have gone through the following threads before posting this question.

Visual Studio Code: Intellisense not working

Visual Studio Code Intellisense not working for Javascript

I have Visual Studio version 1.26.1 on my Windows 10 laptop.

I am learning Node.Js, so I wanted to learn various functionalities in 'FS' module. I created a new file called 'app1.js' in Visual Studio Code, and wrote the following line of code.

fsObj = require('fs');

After this when I typed fsObj. to see what functions/properties are available under the fs object, I get a list with only two objects, which are not elements of the 'fs' module. I do not understand why IntelliSense is not showing the elemetns of 'fs' module. I am pasting a screen shot of the VS Code screen.

enter image description here

KurioZ7
  • 6,028
  • 13
  • 46
  • 65
  • 1
    Those typings should be automatically downloaded, assuming you have node installed. You have "typescript.disableAutomaticTypeAcquisition": false, unchanged in your settings? And "editor.suggestOnTriggerCharacters": true, ? Those are the defaults which you don't want to change. – Mark Aug 22 '18 at 06:35
  • where are these settings? if these settings are in VS Code, how do I access it? – KurioZ7 Aug 22 '18 at 06:37
  • The gear icon in the lower left - then 'Settings'. Then you can 'Search Settings': you should find those two settings in the left panel (which is readonly) and not in the right panel at all if they haven't been changed. I also assume you have internet access so that vscode can download the files necessary for the intellisense. And you installed node? Sorry, basic questions just in case. – Mark Aug 22 '18 at 06:41
  • I have checked these settings and they are unchanged. The strange thing is that if I create a new folder and open that new folder in a new window of VS Code, then I am not facing this issue. But if I open the same folder (in which i see this issue) in a new VS code instance, then I still see this issue. Could this be related to something inside the folder? – KurioZ7 Aug 22 '18 at 06:51
  • I wouldn't think so, does putting const in front of the variable make any difference? It looks like it does for me. So: const fsObj = …. or let or var. – Mark Aug 22 '18 at 07:02
  • Just another of the problems with creating a global variable it appears. – Mark Aug 22 '18 at 07:25
  • adding const in front of the variable worked!. But I would like to understand why it works like this. You can add your comment as answer and I will accept it. Thanks for the help. – KurioZ7 Aug 22 '18 at 07:38
  • @KurioZ7 - for me (in Jul 2019) once I had the settings right and a` jsconfig.json` file, again the intellisense did not immediately work in an existing project. But just creating a new `.js` file in that folder *did* kick intellisense into action. – Annabel Jul 19 '19 at 13:54

1 Answers1

3

Without const, let or var before your variable fsObj, that variable has a 'global' scope. Something about that seems to prevent vscode from being able to assign the proper intellisense parameters to that variable. Adding one of those, like const, provides a different scope where the intellisense works. I cannot explain exactly what is preventing intellisense, perhaps the variable is bound to something higher in the scope chain that prevents it working.

In any case, failing to include const/let/var would result in an error if strict mode was used.

Mark
  • 143,421
  • 24
  • 428
  • 436