Skip to content

🐛 BUG: Formatting failed when there is a React component after a html comment. #438

@Virgil-N

Description

@Virgil-N

Describe the Bug

2025-04-13T09:00:20.17513+08:00 [ERROR] [project.format.local.prettier]: failed, reason: Err(prettier at "/Workspace/Personal/React/react-astro" failed to format buffer

Caused by:
error during message '{"jsonrpc":"2.0","id":3,"method":"prettier/format","params":{"text":"..snip..","options":{"plugins":["/Workspace/React/react-astro/node_modules/prettier-plugin-astro/dist/index.js"],"parser":null,"filepath":"/Workspace/React/react-astro/src/components/Header.astro","prettierOptions":null,"ignorePath":"/Workspace/React/react-astro/.prettierignore"}}}' handling: SyntaxError: Unexpected token (4:18)
2 |


3 |
> 4 |
| ^
5 |

6 | ))
2025-04-13T09:00:20.175311+08:00 [ERROR] Formatting failed: prettier at "/Workspace/React/react-astro" failed to format buffer: error during message '{"jsonrpc":"2.0","id":3,"method":"prettier/format","params":{"text":"..snip..","options":{"plugins":["/Workspace/React/react-astro/node_modules/prettier-plugin-astro/dist/index.js"],"parser":null,"filepath":"/Workspace/React/react-astro/src/components/Header.astro","prettierOptions":null,"ignorePath":"/Workspace/React/react-astro/.prettierignore"}}}' handling: SyntaxError: Unexpected token (4:18)
2 |

3 |

4 |
| ^
5 |


6 | )


my prettier.config.js

/** @type {import("prettier").Config} */

export default {
plugins: ["prettier-plugin-astro"],
overrides: [
{
files: "*.astro",
options: {
parser: "astro",
},
},
],
trailingComma: "es5",
printWidth: 80,
tabWidth: 2,
semi: true,
singleQuote: false,
};


my .prettierignore

Ignore artifacts:

build
coverage

Ignore all HTML files:

*.html

**/.git
**/.svn
**/.hg
**/node_modules
**/public
**/dist

**/.vercel

**/-lock.json
**/
-lock.yaml


my eslint.config.js

export default defineConfig([
...
eslint.configs.recommended,
tseslint.configs.strict,
tseslint.configs.stylistic,
eslintPluginAstro.configs.recommended,
eslintConfigPrettier
...
])

Steps to Reproduce

Write a comment after a React component in an Astro file. Then format.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecosystem: compilerIssue is caused by a bug in the Astro compilerneeds triageIssue needs to be triaged

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions