r/typescript • • Apr 12 '25

Having Problems With Path Aliases

7 Upvotes

(The repo this is all in is here: https://github.com/rjray/smdb)

I have a project that's slowly turning into a monorepo. Right now I have a server sub-directory and a types sub-directory. Soon there will be a client dir as well, that is expected to share type declarations with the server (hence the "types" dir).

I'm trying to use a path alias in the server's tsconfig.json file to simplify references to types:

{
  "compilerOptions": {
    "composite": true,
    "paths": {
      "@smdb-types/*": [
        "../types/src/*"
      ]
    },
    "incremental": true,
    "target": "es2016",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "module": "ES2022",
    "moduleResolution": "Bundler",
    "baseUrl": "src",
    "resolveJsonModule": true,
    "allowJs": true,
    "outDir": "./dist",
    "noEmit": true,
    "isolatedModules": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "noImplicitAny": true,
    "skipLibCheck": true
  }
}

This doesn't work for me, though; none of the files that import types are able to resolve paths that start with @smdb-types/.

There is also a tsconfig.json (much simpler) in the types directory:

{
  "compilerOptions": {
    "composite": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "declaration": true
  },
  "include": ["src/**/*"]
}

What else might I be missing, here? (Repo is linked at the top of the post.)