Hi!
I'm trying to figure out how to use the compilerOptions.paths behavior while retaining the default behavior of compilerOptions.baseUrl.
The following examples assume a folder structure like so:
my-app/
tsconfig.json
package.json
src/
index.ts
something.ts
For example, if we want to support absolute imports via @/, we could configure paths like so:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}
Unfortunately, this has the side effect of permitting import 'src/something'; since baseUrl is set to ..
It appears as if you can replicate the desired behavior by using the following configuration:
{
"compilerOptions": {
"baseUrl": "node_modules",
"paths": {
"@/*": ["../src/*"]
}
}
}
However, I'm not sure if this is functionally equivalent to the following example for all intents and purposes (assuming this worked):
{
"compilerOptions": {
"baseUrl": null, // undefined, whatever
"paths": {
"@/*": ["./src/*"]
}
}
}
Can you confirm if baseUrl: 'node_modules' is identical to baseUrl: undefined? Or are these behaviors different?
Thanks!
Hi!
I'm trying to figure out how to use the
compilerOptions.pathsbehavior while retaining the default behavior ofcompilerOptions.baseUrl.The following examples assume a folder structure like so:
For example, if we want to support absolute imports via
@/, we could configurepathslike so:{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["src/*"] } } }Unfortunately, this has the side effect of permitting
import 'src/something';sincebaseUrlis set to..It appears as if you can replicate the desired behavior by using the following configuration:
{ "compilerOptions": { "baseUrl": "node_modules", "paths": { "@/*": ["../src/*"] } } }However, I'm not sure if this is functionally equivalent to the following example for all intents and purposes (assuming this worked):
{ "compilerOptions": { "baseUrl": null, // undefined, whatever "paths": { "@/*": ["./src/*"] } } }Can you confirm if
baseUrl: 'node_modules'is identical tobaseUrl: undefined? Or are these behaviors different?Thanks!