Skip to content

Prettier 3 and this plugin do not work as intended with Yarn 2 PNP #237

@liamlows

Description

@liamlows

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

For example: v0.5.9

What version of Tailwind CSS are you using?

For example: v3.3.0

What version of Node.js are you using?

For example: v18.18

What package manager are you using?

For example: Yarn 2 with PNP

What operating system are you using?

For example: macOS arm

Reproduction URL

https://github.com/liamlows/Prettier-Issues

NOTE: uses yarn 2 with PNP and zero installs, all you should need to do is ensure corepack enable is run and run yarn to install unplugged dependencies.

Describe your issue
I've been battling this issue for a few weeks now and just got around to finally making a reproduction repo for it.

When attempting to load plugins via prettier version 3, they dont seem to work as intended. I use two plugins one being a import sorting plugin and the other being this plugin. If i try and provide the plugin as stated in the installation instructions for prettier v3, eslint/prettier will fail to load the plugin saying it cannot be found. This is the error ESLint spits out (and prettier when you run a force format):

[Info  - 12:42:11 PM] ESLint server is starting.
[Info  - 12:42:12 PM] ESLint server running in node v18.15.0
[Info  - 12:42:12 PM] ESLint server is running.
[Info  - 12:42:13 PM] ESLint library loaded from: [REPO_PATH]/.yarn/sdks/eslint/lib/api.js
[Error - 12:42:14 PM] An unexpected error occurred:
[Error - 12:42:14 PM] Error: Cannot find package 'prettier-plugin-tailwindcss' imported from [REPO_PATH]/noop.js
    at new NodeError (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:21374:5)
    at packageResolve (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:22354:9)
    at moduleResolve (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:22386:20)
    at defaultResolve (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:22473:16)
    at resolve (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:22490:12)
    at importFromFile (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:22505:16)
    at importFromDirectory (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:23186:10)
    at file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:23203:12
    at async loadPlugin (file://[REPO_PATH]/.yarn/unplugged/prettier-npm-3.1.1-072c31ec21/node_modules/prettier/index.mjs:23208:28)
    at async Promise.all (index 1)

I first had this issue with the import sorting plugin but when i created an issue on their repo (IanVS/prettier-plugin-sort-imports#140), I was provided with a easy fix. Simply unplugging the plugin and adding it to the plugins array in the prettier config with require.resolve(). That worked fine in isolation and format on save and linting worked fine, but the second I tried adding in the tailwind plugin it broke prettier's format on save. I also tried using the require.resolve() trick on the prettier plugin and it did make the cannot find error go away

Currently the repo linked above has it setup with require.resolve() and the linting works but formatting on save does not. If you remove the prettier-plugin-tailwindcss from the plugins array, it will work again and format on save.

I assume this is the correct place for this issue, however let me know if this also needs to be cross-posted to prettier or yarnpkg.

Thanks for any insight as to what the problem is!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions