justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
902 stars 62 forks source link

Does not resolve dynamic import path #156

Closed Edouard127 closed 1 year ago

Edouard127 commented 1 year ago

I tried to import a module dynamically with my directory alias as such

[...]
const imp = (await import("@/client/interactions/" + file)).default(db, ctx) as CommandInteractionHandler
[...]

And it resulted with the following error: Error: Cannot find module '@/client/events/guildCreate.js'

Here is my build command:

"scripts": {
    "build": "tsc && tsc-alias",
  },

I'm using the latest release of tsc-alias

raouldeheer commented 1 year ago

Tsc-alias wil try to resolve to filepath. But because the filepath is not complete it won't find the find and thus not replace the alias. This problem could be solved by using a custom replacer.

Edouard127 commented 1 year ago

Tsc-alias wil try to resolve to filepath. But because the filepath is not complete it won't find the find and thus not replace the alias. This problem could be solved by using a custom replacer.

Can't it just replace the @ ?

andersekdahl commented 1 year ago

It doesn't seem to work on any import() regardless of if it contains a variable like for OP or if it's a static path used for lazy loading.