Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto import in Visual Studio Code only offering absolute path with Lerna subpackages in TypeScript

People also ask

How do you use absolute path in TypeScript?

To be able to use absolute paths in TypeScript we can set the baseUrl property in the tsconfig. json file. With this, we define src as our root directory (for module resolution).


In Visual Studio Code, menu FilePreferencesSettingsUser Settings,

"typescript.preferences.importModuleSpecifier": "relative"

It works fine for me. It imports

import { RegistrationComponent } from '../../abc-modules/registration/registration.component';

in place of

import { RegistrationComponent } from 'app/abc-modules/registration/registration.component';

I landed here from Google and had the opposite problem. My Visual Studio Code instance always imported the relative path even though it was from a different Lerna package.

It turns out that I simply forgot to add the package that it was wrongly importing to my consuming package’s package.json file.

Now, everything works as expected.