Today, baseUrl performs two functions:
- it acts as a prefix for all entries in
paths
- it acts as a potential resolution point for all bare paths
But almost nobody realizes that last part. It means if you have the following:
{
"compilerOptions": {
// ...
"baseUrl": "./src",
"paths": {
"@app/*": ["app/*"],
"@lib/*": ["lib/*"]
}
}
}
An import like
import * as blah from "blah.js";
might resolve to ./src/blah.js.
Usually, developers who wrote this only intended to re-map any modules that started with @app/ and @lib/. Unfortunately people specify a baseUrl because it was previously required to make paths work or as a prefix.
In TypeScript 7.0, we are not reimplementing baseUrl.
Instead, paths will need to manually specify a custom prefix.
{
"compilerOptions": {
// ...
- "baseUrl": "./src",
"paths": {
- "@app/*": ["app/*"],
- "@lib/*": ["lib/*"]
+ "@app/*": ["./src/app/*"],
+ "@lib/*": ["./src/lib/*"]
}
}
}
In the event that you want to maintain the same behavior as before, you can add an additional path mapping for the baseUrl itself:
{
"compilerOptions": {
// ...
"paths": {
// A new catch-all that replaces the baseUrl:
"*": ["./src/*"],
// Every other path now has an explicit common prefix:
"@app/*": ["./src/app/*"],
"@lib/*": ["./src/lib/*"],
}
}
}
In TypeScript 6.0, we will be deprecating this behavior. Using baseUrl will lead to an error which can only be resolved by applying one of the above fixes, or using --ignoreDeprecations.
Today,
baseUrlperforms two functions:pathsBut almost nobody realizes that last part. It means if you have the following:
An import like
might resolve to
./src/blah.js.Usually, developers who wrote this only intended to re-map any modules that started with
@app/and@lib/. Unfortunately people specify abaseUrlbecause it was previously required to makepathswork or as a prefix.In TypeScript 7.0, we are not reimplementing
baseUrl.Instead,
pathswill need to manually specify a custom prefix.{ "compilerOptions": { // ... - "baseUrl": "./src", "paths": { - "@app/*": ["app/*"], - "@lib/*": ["lib/*"] + "@app/*": ["./src/app/*"], + "@lib/*": ["./src/lib/*"] } } }In the event that you want to maintain the same behavior as before, you can add an additional path mapping for the
baseUrlitself:In TypeScript 6.0, we will be deprecating this behavior. Using
baseUrlwill lead to an error which can only be resolved by applying one of the above fixes, or using--ignoreDeprecations.