tsconfig-replace-paths
tsconfig-replace-paths copied to clipboard
Ambiguity with folder modules and imports
We just ran into this with our project, with the typescript (pre-compiled) state of:
# path mappings
"baseUrl": "./src",
"paths": {
"@/*": [
"./*"
],
# src/foo/bar.ts
import { x } from "@/foo"
# src/foo.ts
export const x = 42;
The rewritten output we get in bar.ts is:
require("./")
What I believe may be happening is it's mistakenly assuming a folder import (ala if index.ts existed); however in this circumstance there is no index.ts and it should instead generate "../foo.js"
Does this sound correct or might we have something more nuanced missing in our setup?
Here is what I believe is needed: https://github.com/jonkwheeler/tsconfig-replace-paths/pull/28
I believe I have some free time coming up here soon. Maybe this week or next. Hopefully I can look at this and a few other things while on my paternity leave 🙃🤠
Thanks! and congrats! For what it's worth I switched to using a fork with the PR and it certainly does fix the issue.
I'd phrase the problem as it's not correctly handling the ambiguity of package names when a directory and file have the same base name.
Yo when you get a sec can you send me a dummy repo with the issue?
Before I go digging further, I noticed this is how I have all my repos setup which use this package to publish... I have rootDir
set.
"rootDir": "./src",
"baseUrl": ".",
"paths": {
"@components": ["./src/components"],
"@components/*": ["./src/components/*"],
"@root": ["./"],
"@root/*": ["./*"],
"@utils": ["./src/utilities"],
"@utils/*": ["./src/utilities/*"],
"@vars": ["./src/variables"],
"@vars/*": ["./src/variables/*"]
},
So I'm wondering if the baseUrl is not being accounted for correctly, or simply switching your config to use rootDir
would work.