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

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

Closed
ebeloded opened this issue Aug 19, 2022 · 3 comments · Fixed by #6101
Closed

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

ebeloded opened this issue Aug 19, 2022 · 3 comments · Fixed by #6101
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:create-svelte

Comments

@ebeloded
Copy link

ebeloded commented Aug 19, 2022

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

@dummdidumm
Copy link
Member

This is a duplicate of sveltejs/prettier-plugin-svelte#155 . It's unrelated to SvelteKit, it would happen in all pnpm repos of this kind. The linked issue contains several workarounds, because unfortunately it's not in our hands to fix this, this is an upstream problem.

@dummdidumm dummdidumm closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2022
@ebeloded
Copy link
Author

ebeloded commented Aug 19, 2022

This issue highlights that every new SvelteKit project initialized with pnpm doesn't have the formatting of Svelte files working, even though it can be fixed in this repo.
The frustration I have is that every time I create a new SvelteKit project, I have to update the .prettierrc file, to make the formatting work. This can be fixed in this repo by making the needed adjustments to the config file, no?

@dummdidumm
Copy link
Member

Oh I see, so this is like a feature request to add the solution to the starter template - reopening then.

@dummdidumm dummdidumm reopened this Aug 19, 2022
@dummdidumm dummdidumm added feature / enhancement New feature or request pkg:create-svelte p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. labels Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature / enhancement New feature or request p2-nice-to-have SvelteKit cannot be used by a small number of people, quality of life improvements, etc. pkg:create-svelte
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants