Closed ScilentAssasin closed 1 month ago
This most likely means you're running an old version of Prettier Apex. Please upgrade to latest version, then restart VSCode (that last part is not optional). Let me if that works.
@dangmai I updated for 2.4.1 but is not working too. It even recongnize the prettier as a formater. I downgrade vsCode but is not working anymore. Prettier Issue
There are changes you need to make to the configuration when upgrading to v2, please follow this guide here: https://github.com/dangmai/prettier-plugin-apex/wiki/Upgrading-to-Prettier-Apex-v2
@dangmai even doing this changes I still get the same msg above: Node.js v22.6.0 prettier-plugin-apex@2.1.4 prettier@3.3.3 Vscode: 1.91.1
That needs to be a list, not a string. I'm not that familiar with configuring Prettier using YAML (which it looks like what you're doing), so I might not be of too much help here. Also, make sure you restart VSCode after making that change.
This guide from Salesforce is usually what I recommend people to follow: https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/prettier.html It still works now when I just tried it, so maybe that'd give you some debugging ideas.
@dangmai I created a json file with the same attributes of the YAML file, restarted VsCode like I did before, but now nothing happen lol
["INFO" - 4:10:30 PM] Formatting file:///c%3A/Users/Project/Documents/Org/salesforce-source/src/libs/apex-scheduler/default/main/classes/ApexScheduler.cls ["INFO" - 4:10:30 PM] Using config file at c:\Users\Project\Documents\Org\salesforce-source.prettierrc.json ["INFO" - 4:10:30 PM] PrettierInstance: { "modulePath": "c:\Users\Project\Documents\Org\salesforce-source\node_modules\prettier\index.cjs", "messageResolvers": {}, "version": "3.3.3" } ["INFO" - 4:10:30 PM] Using ignore file (if present) at c:\Users\Project\Documents\Org\salesforce-source.prettierignore ["INFO" - 4:10:30 PM] File Info: { "ignored": true, "inferredParser": null } Any other thoughts?
Do you mind posting the content of c:\Users\Project\Documents\Org\salesforce-source.prettierrc.json
?
Sure:
{ "plugins": ["prettier-plugin-apex"], "trailingComma": "es5", "tabWidth": 4, "singleQuote": true, "printWidth": 140, "apexInsertFinalNewline": false, "overrides": [ { "files": "/lwc//.html", "options": { "parser": "lwc" } }, { "files": ".{cmp,page,component}", "options": { "parser": "html" } } ] }
Could you run this inside your project directory and paste the result here please?
npx envinfo --system --npmPackages 'prettier*' --binaries --npmGlobalPackages 'prettier*' --languages
Also, let's try formatting a file using the CLI instead of VSCode to see if we can rule that out (I typed this out from memory so there may be some issue with the syntax):
npx prettier c:\Users\Project\Documents\Org\salesforce-source\src\libs\apex-scheduler\default\main\classes\ApexScheduler.cls
System: OS: Windows 10 10.0.19045 CPU: (12) x64 AMD Ryzen 5 3600X 6-Core Processor Memory: 3.65 GB / 15.95 GB Binaries: Node: 22.6.0 - C:\Program Files\nodejs\node.EXE npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD Languages: Java: 22.0.2 npmPackages: prettier: 3.3.3 => 3.3.3 prettier-plugin-apex: 2.1.4 => 2.1.4 npmGlobalPackages: prettier-plugin-apex: 2.1.4 prettier: 3.3.3
After running the first command, the formatting is working again, I'll test in more files to see if everything is ok and let you know, but thanks in advance :)
I've been following your tickets and comments, @DiegoCanuto. I'm also facing the same issue. I've tried all the above steps. No luck, though. Could you please help me fix this issue? @dangmai
Could you please post your config files / plugin versions like I did ?
Hey, I had the same issue. I did update to latest version both prettier and prettier-plugin-apex and it now works for me:
It had this effect on my package.json : Versions :
Bellow is my .prettierrc file :
{
"plugins": ["prettier-plugin-apex"],
"trailingComma": "none",
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": {
"tabWidth": 4,
"parser": "lwc"
}
},
{
"files": "**/*.{cls,trigger,apex}",
"options": {
"apexInsertFinalNewline": false,
"printWidth": 140,
"tabWidth": 4
}
},
{
"files": "*.{cmp,page,component}",
"options": {
"parser": "html",
"tabWidth": 4
}
}
]
}
I hope this can help you
@MaxHuet Executing the above commands helped me fix the issue. Thanks for all the help! @DiegoCanuto @dangmai
Summary
Prettier is not working to format apex files.
Steps To Reproduce:
Expected result
Format the file
Actual result
Prettier Error spawnSync
Duplicate Issues for more information:
salesforcedx-vscode#5732
prettier-vscode#3495