Next.js Discord

Discord Forum

Is there a way for VS Code to always use absolute @ paths instead of relative?

Answered
Flammulated Owl posted this in #help-forum
Open in Discord
Flammulated OwlOP
import { CourseCard } from '../card'

The above imports break and are hard to manage and nextjs sets us up with the absolute @ path. Is there a way to have VS Code always use @ path resolution when auto importing.
Answered by joulev
https://stackoverflow.com/a/53137571

almost the same as the above except you use "absolute" instead of "relative"
View full answer

4 Replies

Asian swamp eel
its a tsconfig setting.
{
  "compilerOptions": {
    ...
    "paths": {
      "@/*": ["./src/*"]
    }
    ...
  },
}
Flammulated OwlOP
Thanks! I currently have this
"paths": {
      "@/*": ["./*"],
      "@payload-config": ["./app/(payload)/payload.config.ts"]
    }

But when VS Code is auto importing it will use "./relative/path"
Answer
Flammulated OwlOP
thank you