As I work on creating an npm library with Typescript, I have made use of the paths
setting in tsconfig.json and the module-alias
tool to streamline my imports, allowing me to use syntax like import * from '@/utils'
. However, I have encountered an issue where these paths remain unchanged in the transpiled js files. While this behavior is expected for module-alias
to function correctly, I have noticed that it only works when I use the library locally. Once I install the library via npm and attempt to run it, the import paths no longer function as intended. How can this issue be resolved?
Upon further investigation, I discovered that adding the __moduleAliases
configuration to the package.json file of the project utilizing my library and specifying the path to the library's distribution folder resolves the issue. However, I am still unsure of a definitive solution to this problem.