Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load tailwind config with process.cwd() encounter error in WSL #209

Closed
yunsii opened this issue Aug 26, 2023 · 2 comments
Closed

Load tailwind config with process.cwd() encounter error in WSL #209

yunsii opened this issue Aug 26, 2023 · 2 comments

Comments

@yunsii
Copy link

yunsii commented Aug 26, 2023

What version of prettier-plugin-tailwindcss are you using?

v0.5.3

What version of Tailwind CSS are you using?

v3.3.3

What version of Node.js are you using?

v16.14.0

What package manager are you using?

pnpm

What operating system are you using?

WSL

Reproduction URL

https://github.com/yunsii/prettier-plugin-tailwindcss-reproduction-20230826

Describe your issue

I have created a tailwindcss plugin, it need to configure with process.cwd(), Tailwind CSS intelliSenece works well, but prettier-plugin-tailwindcss encounter error like:

image

It looks like prettier-plugin-tailwindcss not change dir to correct workspace dir? my tailwindcss plugin config: https://github.com/yunsii/prettier-plugin-tailwindcss-reproduction-20230826/blob/master/tailwind.config.ts#L13

@yunsii yunsii changed the title load tailwind config with process.cwd() encounter error in WSL Load tailwind config with process.cwd() encounter error in WSL Aug 26, 2023
@thecrypticace
Copy link
Contributor

Hey! So the Prettier plugin loads files relative to the Prettier config. It doesn't consult or change the current working directory because doing so can cause other problems.

For example, we'd have to change the CWD just before loading the config and then change it back at the end of parse() because doing so has the potential to invalidate assumptions in Prettier itself. Additionally, in environments like VSCode, Prettier extension loads Prettier into the VSCode extension itself in a worker thread. Worker threads do not support process.chdir() and even some operating systems don't support the idea of per-thread working directories. Additionally, in VSCode the CWD in an extension is an ill-defined concept because the working directory of the extension host is often unrelated to the actively-edited workspace.

In your situation it'd be better to use something like __dirname in your Tailwind config file to make the path relative to the file itself rather than the directory in which you happened to run the prettier command.

@yunsii
Copy link
Author

yunsii commented Aug 29, 2023

Thanks for your detailed explanation, and __dirname works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants