Using TypeScript Aliases

By default, Medusa doesn't support TypeScript aliases in production.

If you prefer using TypeScript aliases, install following development dependencies:

Where tsc-alias is a package that resolves TypeScript aliases, and rimraf is a package that removes files and directories.

Then, add a new resolve:aliases script to your package.json and update the build script:

package.json
1{2  "scripts": {3    // other scripts...4    "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",5    "build": "npm run resolve:aliases && medusa build"6  }7}

You can now use TypeScript aliases in your Medusa application. For example, add the following in tsconfig.json:

tsconfig.json
1{2  "compilerOptions": {3    // ...4    "paths": {5      "@/*": ["./src/*"]6    }7  }8}

Now, you can import modules, for example, using TypeScript aliases:

Code
import { BrandModuleService } from "@/modules/brand/service"
Was this chapter helpful?
Edit this page
Ask Anything
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break