javascriptnode.jsvisual-studio-codeauto-import

Does the new VSCODE 1.18 JS/TS auto-import work with npm-installed nodelibs?


I am trying out the new auto-import feature with a JS file in a simple project.

I installed mongoose with npm and saved a new blank js file that I am editing. I expect that after I type const Schema = mongoose. that I should see an intellisense popup menu with mongoose nodelib suggestions and, if I select one, VSC should add an import/require statement for mongoose at the top of the file. I am seeing "Schema" in the intellisense menu, but nothing happens after I select it.


Solution

  • Auto-imports in VS Code 1.18 cannot create import * as X from 'Y' style imports, only import { x } from Y. Support for the former is tracked by https://github.com/Microsoft/TypeScript/issues/19630

    In your example, you should be able to just start typing out Schema to get an auto import suggestion that adds import { Schema } from 'mongoose'