link-module-alias icon indicating copy to clipboard operation
link-module-alias copied to clipboard

not working on compiling ts to js

Open m0hdasif opened this issue 4 years ago • 4 comments

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

m0hdasif avatar Feb 11 '20 21:02 m0hdasif

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.

Rush avatar Feb 11 '20 21:02 Rush

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

khuezy avatar Feb 20 '20 05:02 khuezy

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.

m0hdasif avatar Mar 01 '20 18:03 m0hdasif

Same issue !

albertcito avatar Nov 24 '20 12:11 albertcito