You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using SublimeText 4: Prettier defaults to HTML parser for .svelte files causing formatting errors with JavaScript/rune code. The issue can temporarily resolve after HTML changes because this triggers a different parser selection.
Root cause: Prettier needs explicit --parser=svelte and --plugin=prettier-plugin-svelte arguments to correctly format Svelte files.
My current workaround: use a wrapper script that enforces correct parser selection based on file extension.
Original issues
When modifying JavaScript code in a Svelte 5 component with runes, Prettier throws a syntax error. However, making any whitespace change in the HTML part makes Prettier work again.
Steps to Reproduce
Start with this minimal example that uses Svelte 5 runes:
I found the root cause of this issue. The error occurs because Prettier is incorrectly using the HTML parser instead of the Svelte parser.
Here's my complete working (User) configuration for Sublime Text with JsPrettier that fixes the issue for svelte files but incorrectly formats JS files.
I've tried a lot of combinations of .prettierrc.js (es6 formatted) and sublime JsPrettier.sublime-settings, but specifying parsers by file type seems to be impossible.
As workaround I now use a bash script prettier-wrapper.sh that applies the correct settings:
hkjens
changed the title
Prettier fails on script changes but works after HTML whitespace change (Svelte 5)
SublimeText 4: Prettier parser conflict with Svelte files requires manually specifying Svelte parser
Jan 23, 2025
Uh oh!
There was an error while loading. Please reload this page.
Description
When using SublimeText 4: Prettier defaults to HTML parser for .svelte files causing formatting errors with JavaScript/rune code. The issue can temporarily resolve after HTML changes because this triggers a different parser selection.
Root cause: Prettier needs explicit --parser=svelte and --plugin=prettier-plugin-svelte arguments to correctly format Svelte files.
My current workaround: use a wrapper script that enforces correct parser selection based on file extension.
Original issues
When modifying JavaScript code in a Svelte 5 component with runes, Prettier throws a syntax error. However, making any whitespace change in the HTML part makes Prettier work again.
Steps to Reproduce
Error message
Expected Behavior
Prettier should format the file without errors, regardless of whether changes are made to the script or HTML sections.
Environment
Additional Notes
The text was updated successfully, but these errors were encountered: