[TRI-3988] Support imports with aliases inside the trigger.config file
Problem
If you are using imports in your trigger.config file with aliases you've defined in your tsconfig.json paths, you will get an error like this:
X Error: Cannot find module '@services/environment'
You can't use import aliases that you've setup in your tsconfig.json file inside of the trigger.config.ts file. They work in all other files inside the /trigger folder but just not in this file.
They don't work because we use https://github.com/unjs/c12 to load the config file and it doesn't automatically read tsconfig aliases.
https://github.com/unjs/jiti/issues/166
Workaround
If you experience this problem, for now you can change the path to a relative folder path import.
Potential built-in solution
There is an alias option when using jiti and it looks like we might be able to read the relevant tsconfig paths and populate this with them. https://github.com/unjs/jiti?tab=readme-ov-file#alias
From SyncLinear.com | TRI-3988
Hey @matt-aitken please assign this issue to me?
npm install tsconfig-paths -D
import 'tsconfig-paths/register'
@matt-aitken, I've tested what @guendev said and it worked.
You just need to install the package in the repository and import the 'tsconfig-paths/register' in every trigger file that you need to use or invoke something that use import aliases.
Thanks @guendev for helping 🙌
@matt-aitken, I've tested what @guendev said and it worked. You just need to install the package in the repository and import the
'tsconfig-paths/register'in every trigger file that you need to use or invoke something that use import aliases.Thanks @guendev for helping 🙌
Actually, you just need to import it at trigger.config.ts