-
Notifications
You must be signed in to change notification settings - Fork 36
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: No parser could be inferred for file: Author.astro when using pnpm #97
Comments
note that when I am using yarn 2, I get
|
This is a bug from Prettier itself. See prettier/prettier#8056 |
I was able to get it to work based on this comment To get the prettier cli to behave with pnpm, you can do the following:
Also, to get it to work with vscode, you must also do the following:
overrides: [
{
files: '**/*.astro',
options: { parser: 'astro' },
},
], |
I use pnpm workspace (same structure as the official astro.new "component" template) and this is the only VSCode setup that works for me: On your project root, add {
"folders": [
{
"path": ".."
}
],
"settings": {
"prettier.documentSelectors": [
"**/*.astro"
],
"[astro]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
}
}
}
The prettier config ( |
@ekafyi I still couldn't get my .astro files to format on save using VS workspace. Would you mind sharing your repo or codesandbox? The only thing that worked for me was running Are you using this VS Code Prettier extension, too? https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode |
@djmtype The code is in a private repo, going to make a simple reproduction when i have the time. Yes, I use In the meantime, if you want the - "format": "yarn prettier -w . --plugin-search-dir=."
+ "format:astro": "yarn prettier -w src/components/*.astro --plugin-search-dir=." Just curious — does it also not work when you paste these options to your global VSCode settings ("Preferences: Open Settings (JSON)")?
|
@ekafyi Thanks for the tip! |
@ekafyi I haven't had any luck with pnpm in regards to getting my files to format on save when using global or workspace settings. pnpm will only work as a separate task. npm works without issue. But, I'd rather not have duplicate modules on my machine. @sarah11918 started an instruction guide, so I posted there too: |
This "prettier": {
"documentSelectors": [
"**/*.astro"
]
}, leads to Something like this But of course, nothing from above gives a result. 😿 This would be nice as a |
We unfortunately cannot fix the underlying issue ourselves, however can definitely document this much better. As such instructions on how to get this working with pnpm has been added to the plugin's README in the next version. Additionally, we're in the process of adding instructions inside the Astro docs too (withastro/docs#831). Hopefully, that'll cover it much better! |
I encountered this error too in my last pnpm project and solved it by moving my prettier config to the file
|
When I run My
|
Do you have the Prettier plugin in your Prettier config? Prettier 3 deprecated plugin auto load and now plugins need to be manually specified in your config. |
This is the contents of my
|
Hmm, it seems like the plugin doesn't get loaded. Perhaps try replacing |
Describe the Bug
When trying to format / check an
.astro
file, it does not seem to be able to recognize the formatter when using pnpm.It does work with
yarn
.Steps to Reproduce
npm init astro
using template blogpnpm install
pnpm i --save-dev prettier-plugin-astro
pnpm prettier src/components/Author.astro -c
The text was updated successfully, but these errors were encountered: