link-module-alias
link-module-alias copied to clipboard
not working on compiling ts to js
@Rush,
I really liked your package, but I ran into issue while I was implementing the links in typescript. It is working fine in typescript but got the following issue on compiling the project into JavaScript.
Error: Cannot find module '@utils/httpService
Please tell me, how can I resolve the issue?
Could you provide a sample repo where the problem occurs? I think I dealt with a similar issue but would need to see what was the problem in your case.
@m0hdasif tsconfig.json:
"rootDir": "src",
"baseUrl": ".",
"paths": {
"@utils/*": ["src/utils/*"]
}
package.json:
"_moduleAliases": {
"@utils": "src/utils"
},
You'll want to prefix the link-module-alias
before all your node
command
e.g.: nodemon.json:
"exec": "link-module-alias && node...
Personally, I'd just alias the root: tsconfig.json:
"paths": {
"~/*": ["src/*"]
}
package.json:
"~": "src"
Thanks @khuezy for suggestion, I made it work by making following tweaks in expressJs application:
tsconfig.json:
"rootDir": "src",
"baseUrl": ".",
"paths": {
"@utils/*": ["src/utils/*"]
}
package.json:
- creating links post-build
"scripts": {
"preinstall": "which link-module-alias && link-module-alias clean || echo",
"postinstall": "link-module-alias",
"build": "rm -rf build/ && tsc && link-module-alias",
"start": "node build/src/index.js"
},
"_moduleAliases": {
"@utils": "build/src/utils"
}
Hi @Rush,
I am facing the said issue while using serverless-plugin-typescript
plugin in server-less application. I need to check if I could run link-module-alias
command with above tweaks post compilation to JavaScript while running/deploying the server-less application.
Same issue !