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: [error] No parser could be inferred for file #428

Open
daelmaak opened this issue Sep 5, 2024 · 4 comments
Open

🐛 BUG: [error] No parser could be inferred for file #428

daelmaak opened this issue Sep 5, 2024 · 4 comments

Comments

@daelmaak
Copy link

daelmaak commented Sep 5, 2024

Describe the Bug

I realize this one is very similar to #97 but none of the suggested solutions work for me. I use the suggested config

// .prettierrc.mjs
/** @type {import("prettier").Config} */
export default {
  plugins: ['prettier-plugin-astro'],
  overrides: [
    {
      files: '*.astro',
      options: {
        parser: 'astro',
      },
    },
  ],
};

and VSCode configuration

{
  "prettier.documentSelectors": ["**/*.astro"],
  "[astro]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

and the formatting doesn't work both when doing it directly in VSCode

["INFO" - 6:22:27 PM] File Info:
{
"ignored": false,
"inferredParser": null
}
["WARN" - 6:22:27 PM] Parser not inferred, trying VS Code language.
["ERROR" - 6:22:27 PM] Failed to resolve a parser, skipping file. If you registered a custom file extension, be sure to configure the parser.

and from command line with prettier --write **/*.astro src

prettier --write **/*.astro src
[error] No parser could be inferred for file: src/components/about-experience.astro

I'm using prettier 3.3.3 and your plugin 0.14.1. My project is private but is directly based on https://astro.build/themes/details/aria/

Steps to Reproduce

Try to add prettier to https://github.com/ccbikai/astro-aria and make it format *.astro files, it won't work.

@jorenbroekema
Copy link

Same issue here, followed README.md but simply doesn't work with latest dependencies

@Theiaz
Copy link

Theiaz commented Oct 24, 2024

Same issue for me, made it work using --plugin option:

prettier --plugin=prettier-plugin-astro --write **/*.astro .

@bnjmnrsh
Copy link

I don't know if this may help some, or if it is unrelated, but if you are running into these issues it may be worth checking to see if there are any conflicting settings in your VSCode config.

In my setup what started as [No parser could be inferred for file](https://github.com/withastro/prettier-plugin-astro/issues/428#top) later also started throwing Cannot find package 'undefined' imported from /Users/anachronistic/Documents/WebDev/memorialforestdg.github.io/.prettierrc.

The latter was the result of an erroneous setting in my VSCode settings.json for prettier: "prettier.configPath": ".prettierrc",

Once this was removed everything fell into place.

@joska-p
Copy link

joska-p commented Dec 30, 2024

bnjmnrsh thanks for your comment. it helped me. i was struggling to find out that my prettier config file was prettierrc.mjs instead of .prettierrc.mjs
just a dumb error make me loose 2hours.
Thanks

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

5 participants