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

🐛 BUG: Couldn't load prettier or prettier-plugin-astro when using Yarn PnP #655

Open
imballinst opened this issue Sep 26, 2023 · 2 comments
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: yarn-pnp Issue specific to yarn pnp support (scope)

Comments

@imballinst
Copy link

imballinst commented Sep 26, 2023

Describe the Bug

I am using Yarn berry in my project, which I believe is already supported: #370 (and I could install the Astro language server nicely).

However, I'm getting this message/error when I'm opening an .astro file:

Couldn't load prettier or prettier-plugin-astro. Formatting will not work. Please make sure those two packages are installed into your project.

I tried to replicate it in a repository (using Codespaces: https://github.com/imballinst/astro-yarn-berry-pnp), and it seems I am able to replicate the behavior. Do you might have an idea on what I should do, or could you point me out to a documentation that I could use? Thanks! 🙇‍♂️

Steps to Reproduce

With the sample repository:

  1. git clone [email protected]:imballinst/astro-yarn-berry-pnp.git
  2. Open the folder in VS Code
  3. Go to src/layouts/Layout.astro
  4. See notification popping up on bottom right, and we can't quite prettify Astro files

image

This is despite that prettier is already installed as devDependencies and I have the Prettier SDK already:

"devDependencies": {
  "@astrojs/language-server": "2.3.3",
  "prettier": "3.0.3"
}

In the extension output, I got this:

["ERROR" - 10:05:32 AM] Failed to resolve a parser, skipping file. If you registered a custom file extension, be sure to configure the parser.
@Princesseuh
Copy link
Member

Princesseuh commented Sep 26, 2023

Yarn PnP is very annoying and has caused so much issues over the years for this project. It's not possible to test correctly in CI for us and no one in the team uses it, so it's very possible there's a regression there.

@Princesseuh Princesseuh added bug feat: yarn-pnp Issue specific to yarn pnp support (scope) labels Sep 26, 2023
@imballinst
Copy link
Author

Thanks for the reply @Princesseuh! I am beginning to think that maybe Prettier in Yarn PnP was never implemented? Looking at this part of that old PR, perhaps this part:

const rootDir = ctx.env.uriToFileName(ctx.project.rootUri.toString());
const prettier = importPrettier(rootDir);
const prettierPluginPath = getPrettierPluginPath(rootDir);

should be something like this instead (?) not sure.

const prettierRuntimeConfig = workspace.getConfiguration('prettier');
const workspacePrettierPath = runtimeConfig.get<string>('prettierPath');

const rootDir = workspacePrettierPath ?? ctx.env.uriToFileName(ctx.project.rootUri.toString());
const prettier = importPrettier(rootDir);
const prettierPluginPath = getPrettierPluginPath(rootDir);

Because at the moment, it seems as if it will always try to use the Prettier from node_modules (which doesn't exist in Yarn PnP). Other features work perfectly, like the autocorrect, autocompletions, typings, and stuff (apart from very minor Astro global not having proper typing, I assume it's probably related).

@Princesseuh Princesseuh added - P3: minor bug An edge case that only affects very specific usage (priority) and removed bug labels Nov 12, 2023
@Princesseuh Princesseuh changed the title 🐛 BUG: Couldn't load prettier or prettier-plugin-astro. Formatting will not work. 🐛 BUG: Couldn't load prettier or prettier-plugin-astro when using Yarn PnP Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) feat: yarn-pnp Issue specific to yarn pnp support (scope)
Projects
None yet
Development

No branches or pull requests

2 participants