VS Code is auto-importing everything relative to baseUrl
using Node-like non-relative paths, which is what I don't want.
How do I tell VS Code to import everything with relative paths (except for Node modules of course)?
Removing the baseUrl
option is not an option because I need it in order to point fs
imports at a local polyfill of the fs
module.
My tsconfig.json has this:
"baseUrl": "./",
"paths": {
"fs/*": [ "./src/util/FileSystem/*" ]
}
If there's no other way other than removing the baseUrl
option, then that doesn't do any good!
TSConfig paths. A series of entries which re-map imports to lookup locations relative to the baseUrl, there is a larger coverage of paths in the handbook. paths lets you declare how TypeScript should resolve an import in your require/imports. {" compilerOptions ":
To enforce relative path auto imports in VS Code, you can change the importModuleSpecifier setting to value "relative". { "typescript.preferences.importModuleSpecifier": "relative" // ... } The value "non-relative" would create absolute paths based on baseUrl, "auto" ( default setting) selects the shortest path automatically.
There is a problem with this: Compiling the TypeScript code to JavaScript makes it unusable by JavaScript. JavaScript does not understand those module paths. Also, tools like ts-node or ts-jest do not understand these module path imports.
TypeScript by default supports module import. Unlike with those ugly dot slashes, you can configure module paths in tsconfig.json and then use them for import. tsconfig.json.
To enforce relative path auto imports in VS Code, you can change the importModuleSpecifier
setting to value "relative"
.
settings.json (workspace or user):
{
"typescript.preferences.importModuleSpecifier": "relative"
// ...
}
The value "non-relative"
would create absolute paths based on baseUrl
, "auto"
(default setting) selects the shortest path automatically.
For JavaScript there is an analogue setting "javascript.preferences.importModuleSpecifier"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With