trigger.dev icon indicating copy to clipboard operation
trigger.dev copied to clipboard

[TRI-3988] Support imports with aliases inside the trigger.config file

Open matt-aitken opened this issue 1 year ago • 4 comments

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

matt-aitken avatar Nov 13 '24 14:11 matt-aitken

Hey @matt-aitken please assign this issue to me?

yadavshubham01 avatar Nov 19 '24 06:11 yadavshubham01

npm install tsconfig-paths -D import 'tsconfig-paths/register'

guendev avatar Jan 03 '25 09:01 guendev

@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 🙌

pedrosoares-ncs avatar May 13 '25 11:05 pedrosoares-ncs

@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

guendev avatar Jun 03 '25 16:06 guendev