Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Always use alias for automatic imports

Is there a way to force autoimport to always use the alias for importing modules in a [email protected] project using VSCode?

I would like to use them even when it's a sibling component, no exceptions, so instead of

import { Navbar } from "./components";

I would like to force auto-import to use the alias in all cases:

import { Navbar } from "@/components";
like image 641
Guillermo Brachetta Avatar asked Dec 06 '25 07:12

Guillermo Brachetta


1 Answers

Assuming you have your tsconfig.json (or jsconfig.json) setup for path aliases correctly, you can change VSCode's preferences in your User Settings. Search for "Import Module Specifier" and you should see two entries - one for TypeScript and one for JavaScript. To always use the path alias, change these to non-relative.

settings to change in vscode

If you prefer editing your settings.json directly, the keys are:

{
  //...
  "typescript.preferences.importModuleSpecifier": "non-relative",
  "javascript.preferences.importModuleSpecifier": "non-relative",
  //...
}

If you want to do this at a per-project level, instead change these for your Workspace Settings.

like image 76
Michael Cheng Avatar answered Dec 08 '25 05:12

Michael Cheng



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!