Path aliases with TypeScript in Node.js

Lars Wächter on February 06, 2019

Some days ago I included path aliases in my TypeScript Node.js projects. Since they make the code look much clearer in my opinion I like to show yo... [Read Full]
markdown guide


Also I find out that if we have webpack in project we just use resolve.alias option:

  resolve: {
    extensions: ['.js', '.ts', '.tsx', '.styl'],
    mainFields: ['module', 'browser', 'main'],
    alias: Object.keys(tsconfig.compilerOptions.paths).reduce((aliases, aliasName) => {

      aliases[aliasName] = path.resolve(__dirname, `src/${tsconfig.compilerOptions.paths[aliasName][0]}`)

      return aliases
    }, {})

Thank you! I read several posts about using path aliases and thought it was perfect for my project, but I hit the *cannot find module" issue. I was banging my head off the desk all afternoon. It's been really difficult to find anything on this.


How complex is the folder organization for your source code? I had looked into this but it doesn't have as much value with flatter source-orgs


The complexity of my folder organization depends on the project. Mostly I have some root folders like: config, rest, services that I declare path aliases for. Inside these I have my components for example.


I found that using extension to import works good enough and not require much logic.

code of conduct - report abuse