Open mschering opened 2 years ago
+1 bug with default replacer
{
"baseUrl": ".",
"outDir": "lib",
"paths": [
"#app": [
"node_modules/nuxt/dist/app"
]
]
}
Alias after config.aliasTrie.search
{
shouldPrefixMatchWildly: false,
prefix: '#app',
paths: [
{
path: 'node_modules/nuxt/dist/app',
basePath: '/my/user/dir/projects/project-name/lib',
isExtra: false
}
]
}
After normalize path /my/user/dir/projects/project-name/lib
Can't say debug
log, don't understand how enable it with programatically use
Have same alias for another module in node_modules
, it worked, because normalize path try convert #kb/consts/error-code
to /my/user/dir/projects/project-name/lib/consts/error-code
and cannot find file(it doesn't exist)
{
"#kb/*": [
"node_modules/some-package/dist/*"
],
}
I ran into this issue today, and have a workaround that works in my project.
Here is the tsc-alias
command i'm running:
tsc-alias --verbose --debug
Here is my relevant tsconfig.json
:
{
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
"paths": {
"@/shared/*": [ "../shared/*" ],
},
},
}
With the above configuration, i get the following debug output, indicating the failure:
tsc-alias debug: default replacer - alias: {
shouldPrefixMatchWildly: true,
prefix: '@/shared/',
paths: [
{
path: '../shared/',
isExtra: true,
basePath: '/path/to/project/dist/shared/shared'
},
[length]: 1
]
}
tsc-alias debug: default replacer - absoluteAliasPath: '/path/to/project/dist/shared/shared'
tsc-alias debug: default replacer - Invalid path
Of note in this debug output is that the shared
dir appears twice in the basePath
that gets calculated by tsc-alias
. This problem only surfaced when we moved our shared dir from two levels up to one level up.
After many hours of troubleshooting, we realized that the configuration in the tsconfig.json
works for our tsc
command, but not for our tsc-alias
command. Our solution was to provide 2 paths, one that would work with tsc
, and one that would work with tsc-alias
:
{
"compilerOptions": {
"outDir": "./dist",
"baseUrl": "./",
"paths": {
"@/shared/*": [
// This is the correct path, which works with `tsc`
"../shared/*",
// This is the hacked path, which is necessary to enable `tsc-alias`.
// This appears to be a bug in `tsc-alias` related to going up only
// a single parent directory, since this didn't happen when our
// shared dir was one level higher...
// A value of `../*` works here too, but I decided to use a less
// cryptic path.
"../../shared/*",
],
},
},
}
Hopefully this helps someone.
thank you @brainthinks that worked for us 🙏
@brainthinks did a great job digging into the issue: the alias.basePath
is constructed incorrectly.
@justkey007 Please, take a second look into this, whenever you have a spare time and motivation. Also, good job adding an informative debug system, it really helped.
Hi,
My problem is that ts-alias never replaces any import because it resolves to an invalid path. All paths resolve to/goui/dist/... instead of /goui/dist...
I have this tsconfig:
Here's the debug output:
Am I doing something wrong or is it a bug?
Thanks!
Best regards, Merijn