-
Notifications
You must be signed in to change notification settings - Fork 97
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
Formatting doesn't work (with newly released Prettier v2.1.0) #123
Comments
I've spent the last 5 hours trying to figure out what in God's name is preventing me from formatting my files. I have one vs code project open from yesterday which is still formatting perfectly. I diffed all relevant files in the new project with the old one and only found that the version of Prettier had been updated. Even after changing that, I still can't get it to work. Any idea what the problem is? |
For context, this gist contains my:
|
The problem seems to be this line. The plugin uses it to check if the AST node is the root level. but for some reason, the new prettier version removes the 'tokens' property. The current workaround is to locate your prettier-plugin-svelte in node_modules . find the isASTNode function and remove && 'tokens' in n .
|
This change alters the code such that we are independent of property-changes of both Svelte and Prettier by adding a `__isRoot`-property to the parser output root. Fixes sveltejs#123
This change alters the code such that we are independent of property-changes of both Svelte and Prettier by adding a `__isRoot`-property to the parser output root. Fixes #123
@dummdidumm Its solved now ? |
Working for me. Thanks! |
@michaelwooley cool Edited : Seems still not working for me (no formatter found etc) My settings :
What is your configuration @michaelwooley ? My configuration that works currently :
But I think format on save not working |
@x4080 sorry should have elaborated a bit more on the sense in which this is working for me. If I use versions:
Then the following command works fine:
On VS Code there is a solution but just upgrading doesn't work. The language server is using local versions of the packages. It also assumes a dependency of 2.0.5 for prettier. So within your project try:
I haven't checked to see if having v1.1.1 of the plugin is critical to making it work but it doesn't hurt. Finally, restart VS Code, etc. to make sure that everything starts afresh. Hope that helps? |
@michaelwooley Thanks for reply, I just use svelte extension - so we need to use npm to make it work then, didnt know that. I'll try it later |
We didn't update the prettier version of svelte-language-server so the bundled one should be |
How to get this working again
More indepthWe deployed an update of the VSCode extension which contains the v1.1.1 of To get formatting again, you also have to update your
|
@michaelwooley and @dummdidumm I seems cant make it work, here's what I did :
restart the vscode, open file .svelte, format document and no formatter found This become like rocket science :) |
@michaelwooley This command work though : (must add npx) |
@x4080 could you create a gist with:
[edit: getting this info] |
@michaelwooley Thanks for helping me, how to get output from the language server ? Maybe this is why my setting not working ? |
Formatting in my editor works with the following setup:
That's what it took for formatting to work again (though, the only thing I changed was the prettier version, one might have settings different from mine that are affecting VS Code). |
@michaelwooley Solve it ! It seems that my vs code is not updating, it said that cannot format if version is lower than xxxx, I force it to update and now it works But before that, I installed svelte-check like @solidstatejake mentioned above Thanks for all guys |
My setup was somewhat like that (I didn't check prettier version) and all I had to do was to reload the window (ctrl+shift+p, then type "Reload Window") and VSCode started formatting svelte files again. Thanks! |
I was having this same issue and found if I removed the .prettierrc file, then it started working as normal. Edit: I commented out "plugins": ["prettier-plugin-svelte"] from the .prettierrc file and saved and the formatting seems to work with just that. Hope this helps! |
Thank you! ❤️ This fixed it for me. Remove |
I had this in the output from Error: Cannot find module 'prettier-plugin-svelte'
Require stack:
- /Users/me/sveltekit-app/node_modules/prettier/index.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/importPackage.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/configLoader.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/Document.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/index.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/server.js
- /Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/bin/server.js
at Module._resolveFilename (node:internal/modules/cjs/loader:987:15)
at resolve (node:internal/modules/cjs/helpers:108:19)
at /Users/me/sveltekit-app/node_modules/prettier/index.js:51552:21
at Array.map (<anonymous>)
at Object.load (/Users/me/sveltekit-app/node_modules/prettier/index.js:51544:61)
at Object.load [as loadPlugins] (/Users/me/sveltekit-app/node_modules/prettier/index.js:16864:26)
at /Users/me/sveltekit-app/node_modules/prettier/index.js:51618:28
at Object.format (/Users/me/sveltekit-app/node_modules/prettier/index.js:51640:12)
at SveltePlugin.formatDocument (/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/plugins/svelte/SveltePlugin.js:66:40)
at async PluginHost.tryExecutePlugin (/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/plugins/PluginHost.js:321:20) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/Users/me/sveltekit-app/node_modules/prettier/index.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/importPackage.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/configLoader.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/Document.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/lib/documents/index.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/dist/src/server.js',
'/Users/me/.vscode/extensions/svelte.svelte-vscode-106.4.1/node_modules/svelte-language-server/bin/server.js'
]
} Maybe that can help figure out the problem? For now
Works for me, so I'll go with that, but it seems not the right solution, as CI and such probably need that when running formatting. |
With Prettier v2.1.0, VSCode stops formatting
.svelte
files and the Svelte VSCode extension runs intoError: unknown node type: undefined
pointing toprettier-plugin-svelte
in the stacktrace as culprit.The text was updated successfully, but these errors were encountered: