Babel Module Resolver with TypeScript

Robin Wieruch

Here you will learn how to use TypeScript with Babel Module Resolver for aliases that are defined in your .babelrc file:

javascript
{
  ...
  "plugins": [
    [
      "module-resolver",
      {
        "root": ["./"],
        "alias": {
          "@components": "./src/components",
          "@constants": "./src/constants",
        }
      }
    ],
  ]
}

In order to get the same alias mappings to TypeScript, the tsconfig.json file needs to look like this:

javascript
{
  "compilerOptions": {
    ...
    "baseUrl": ".",
    "paths": {
      "@components/*": ["./src/components/*"],
      "@constants/*": ["./src/constants/*"]
    }
  },
  ...
}

Now you can use import statemes with aliases in your TypeScript files too.

Never Miss an Article

Join 50,000+ developers getting weekly insights on full-stack engineering and AI.

AI Agentic UI Architecture React Next.js TypeScript Node.js Full-Stack Monorepos Product Engineering
Subscribe on Substack

High signal, low noise. Unsubscribe at any time.