Skip to content
Advertisement

How to intellisense alias module path in VSCode

I would like VSCode to IntelliSense the module path so I can access it by click.

For example, after configurating jsconfig.json I’m able to access ./src/styled/index by importing its global path.

But I couldn’t figure out how to make it work with an alias @styles

JavaScript

enter image description here

My current jsconfig.json:

JavaScript

Advertisement

Answer

Seems I had to restart VSCode.


Javascript (javascript,javascriptreact file types in VSCode)

An example of jsconfig.json file for reference:

JavaScript

An example of how styles/index looks like:

JavaScript

Will allow import (with IntelliSense):

JavaScript

For a bonus: aliases.js, which is a helper which I use to define aliases in webpack config files, it helps to not repeat yourself, for example when using the same aliases in storybook and for the application itself.

JavaScript

Typescript (typescript,typescriptreact files)

At tsconfig.json use the compilerOptions.paths option, notice that the paths are relative to baseUrl:

JavaScript

This allows aliases (with IntelliSense), for example:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement