Skip to content

How to use path alias in packages? #128

@depsimon

Description

@depsimon

I want to setup path aliases in packages (import from ~/...) to replace relative imports with aliased imports.

Heer's my configs:

// packages/ui/package.json
{
  "name": "@workspace/ui",
  "type": "module",
  "exports": {
    "./*": "./src/*"
  },
  ...
}
// packages/ui/tsconfig.json
{
  ...,
  "compilerOptions": {
    ...
    "paths": {
      "~/*": [
        "./src/*"
      ],
    },
  }
}

Inside the ui lib package, everything seems fine, no errors whatsoever. But as soon as I import a UI component in my Remix app, I'm getting TS errors:

../../packages/ui/src/components/Button/index.tsx:2:22 - error TS2307: Cannot find module '~/components/Slot' or its corresponding type declarations.

2 import { Slot } from "~/components/Slot";

In my case, Button imports Slot from ~/components/Slot.
If I import from "../Slot"; all is fine again as it doesn't use alias anymore.

Also components that don't import other components or utils don't throw the error.

I am not using tsup.

Am I missing something obvious? Or is this not supported at all? It's probably not a limitation on Remix side, but rather on TS/monorepo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions