'module-alias not working with esm if called from specific file

I want to use module-alias with esm. I have already found an answer here. The problem is that I am using it manually, like this:

import * as path from 'path';
import * as moduleAlias from 'module-alias';
moduleAlias.addAlias('@', path.join(process.cwd(), 'dist', 'server'));

How can I fix it if it is not directly called by module-alias/register but from this code?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source