Reputation: 4418
I am using Visual Studio Code 1.20.0 on Windows. My intellisense is not working correctly eg: visual studio code is not able to detect that the youtubedl package has getinfo method. Would the community have inputs on what I need to do to get intellisense working correctly? If not, how can I browse an NPM package to find the various methods exposed by it(In .Net we can do the same using an object explorer)?
Upvotes: 6
Views: 12657
Reputation: 3037
It might not be your case, but in mine it was fairly straightforward. I installed an npm package and for some reason VS Code's language service didn't pick it up, so autocompletion was not working for that package.
Restarting VS Code had the Intellisense autocompletion be refreshed.
Upvotes: 0
Reputation: 50258
If you're using ES6 imports, you'll need a jsconfig.json
file in the root of your project.
Below is an example config, with allowSyntheticDefaultImports
being the important option that will likely solve your problem.
Don't forget to restart VSCode afterwards.
{
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
},
"include": [
"src/**/*"
],
}
Upvotes: 4
Reputation: 1938
In my case on Ubuntu 18.04 and :
VSC as following
Version: 1.40.1 Commit: 8795a9889db74563ddd43eb0a897a2384129a619 Date: 2019-11-13T16:49:30.162Z Electron: 6.1.2 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Linux x64 4.15.0-70-generic snap
Considering that contrary of what docs says:
TypeScript and JavaScript Language Features is not listed under the extensions
What did made the intelligent code completion for Javascript was this 2 interdipendent steps:
create jsconfing.json
disable the "JavaScript and TypeScript Nightly" default extention
Of course restart the VSC
Upvotes: 0
Reputation: 381
I'm also meet the same problem. And I'm using VS Code v1.24.0 on the macOS High Sierra.
referred from the page: https://code.visualstudio.com/docs/languages/javascript#_fixing-npm-not-installed-warning-for-automatic-type-acquisition
.
VS Code automatically downloads and manages the type declaration files(*.d.ts) for JS with the ATA(Automatic Type Acquisition) feature, but it also not works for me.
So I find this:
https://github.com/DefinitelyTyped/DefinitelyTyped
. we can download the type declaration files manually with this kind command:
npm install --save-dev @types/name_for_the_ package
and you can choose to use the extension Types auto installer in VS Code to help you download type declaration files when you run npm install
. maybe sometimes the Types auto installer
will also not work, but you can download the types file manually anyway.
after you install the types files, you will get the intellisense again.
For the most part, type declaration packages should always have the same name as the package name on npm, but prefixed with @types/, but if you need, you can check out http://microsoft.github.io/TypeSearch/ to find the package for your favorite library.
In some situation, you may need to add a jsconfig.json
file to your project.
The presence of a jsconfig.json file in a directory indicates that the directory is the root of a JavaScript project. jsconfig.json specifies the root files and the options for the language features provided by the JavaScript language service. For common setups a jsconfig.json file is not required, however, there are situations when you will want to add a jsconfig.json.
Not all files should be in your JavaScript project (for example, you want to exclude some files from showing IntelliSense). This situation is common with front-end and back-end code.
Your workspace contains more than one project context. In this situation, you should add a jsconfig.json file at the root folder for each project.(the jsconfig.json can have no content.)
You are using the TypeScript compiler to down-level compile JavaScript source code.
Upvotes: 2