postcss / postcss-load-config

Autoload Config for PostCSS
MIT License
642 stars 72 forks source link

Typescript paths alias doesn't resolve #266

Open howagain opened 1 month ago

howagain commented 1 month ago

Trying to use a shared tailwind config in an integrated Nx monorepo. The module resolution is all done with typescript path aliasing rather than package manager workspace module resolution. The shared tailwind config works just fine if I do a relative import ../../libs/shared-tailwind-config.ts but fails with a module failed to resolve if I have a path alias in my tsconfig of @tw: [/libs/shared-tailwind-config.ts]. I have included the postcss.config.ts file in my tsconfig.josn and VS code is able to recognize the import alias correctly in the file.

brc-dd commented 1 month ago

What are you using for TS support? jiti or tsx? tsx supports tsconfig paths, jiti supports custom JITI_ALIAS format.

howagain commented 1 month ago

Vite, so esbuild I believe.

On Tue, Jul 16, 2024 at 3:04 AM Divyansh Singh @.***> wrote:

What are you using for TS support? jiti or tsx?

— Reply to this email directly, view it on GitHub https://github.com/postcss/postcss-load-config/issues/266#issuecomment-2230390371, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOELQY3LDYPXUPTX7KHOGJ3ZMTOZ3AVCNFSM6AAAAABK6EB3UWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZQGM4TAMZXGE . You are receiving this because you authored the thread.Message ID: @.***>

brc-dd commented 1 month ago

Vite is using v4 of this module -- ts-node stuff. Install ts-node and tsconfig-paths and configure it in your tsconfig.json - https://typestrong.org/ts-node/docs/paths


Here is a working example if you wanna try that out - https://stackblitz.com/edit/vitejs-vite-htrwaq?file=tsconfig.json,postcss.config.ts,src/foo.ts&terminal=dev

With vite 6, you'll be able to do this without any extra configuration. You'll just need to install tsx instead of ts-node.

The issue can probably be closed here.