Skip to content

Prettier formatting doesn't work when SvelteKit installed with pnpm #6060

@ebeloded

Description

@ebeloded

Describe the bug

After generating new SvelteKit project with pnpm, formatting of svelte files doesn't work.

Reproduction

  1. Generate new SvelteKit project, with prettier formatter
pnpm create svelte@latest kit-prettier
  1. cd kit-prettier
  2. pnpm install
  3. pnpx prettier src/**/*.svelte --write
  4. Error

What's more, VSCode with prettier plugin installed can't format Svelte files, failing with the following error:

Failed to resolve a parser, skipping file. If you registered a custom file extension, be sure to configure the parser

Severity

annoyance

Additional Information

I recognize that the team is aware of this issue because in package.json, the "format" command includes a flag that makes formatting work:
prettier --write --plugin-search-dir=. .

However, this doesn't work for VSCode prettier plugin, which can't locate the svelte-prettier-plugin.

The solution would be to add the following lines in .prettierrc

"pluginSearchDirs": ["."],
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]

With this in place, the VSCode formatting would work and scripts in package.json won't need to have the --plugin-search-dir flag.

Related issue: sveltejs/prettier-plugin-svelte#155

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature / enhancementNew feature or requestp2-nice-to-haveSvelteKit cannot be used by a small number of people, quality of life improvements, etc.pkg:create-svelte

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions