Theo's Typesafe CultTTC
Theo's Typesafe Cult3y ago
8 replies
jairrard

Issue adding import path to tsconfig.js

I wanted to create a path I can import my ui components from to make imports cleaner. Wanted to call the path "@ui" for ".src/components/ui/" but running into compiler issues.

My tsconfig.json looks like

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["es6", "dom", "dom.iterable", "esnext"],
    "baseUrl": "src",
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "noImplicitAny": true,
    "noImplicitThis": true,
    "strictNullChecks": true,
    "paths": {
      "@ui/*": ["./components/ui/*"]
    }
  },
  "include": ["src"]
}


Not sure why my tsconfig.json is this long but it is what it is.

This is how I'm importing my ui components in other files -

import { PageHeading } from "@ui/Headings/PageHeading";

The error I'm getting is
ERROR in ./src/pages/Services/SharedSpace/Spaces.tsx 4:0-55
Module not found: Error: Can't resolve '@ui/Headings/PageHeading'


Been trying to figure out this error for a while and have already -
Restarted TS Server
Restarted VS Code

Don't know what else to do.
Was this page helpful?