3

I have prettier and prettier-plugin-apex node modules installed. Formatting LWC and JSON works fine with prettier but get the below error when formatting Apex files. Never had this issue on my old laptop.

Updated the plugins multiple times and has the latest version of npm.

["ERROR" - 2:57:47 pm] Error formatting document.
Error: 
    at parseTextWithSpawn (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier-plugin-apex\src\parser.js:36:11)
    at Object.parse (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier-plugin-apex\src\parser.js:489:21)
    at Object.parse (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier\index.js:13625:19)
    at coreFormat (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier\index.js:14899:14)
    at format (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier\index.js:15131:14)
    at c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier\index.js:57542:12
    at Object.Success [as format] (c:\Users\user12\VSCodeWorkspace\b2c-ordering-dx\EnergyDX\node_modules\prettier\index.js:57562:12)
    at t.default.<anonymous> (c:\Users\user12\.vscode\extensions\esbenp.prettier-vscode-6.3.2\src\PrettierEditService.ts:492:45)
    at Generator.next (<anonymous>)
    at s (c:\Users\user12\.vscode\extensions\esbenp.prettier-vscode-6.3.2\dist\extension.js:1:9119)
["INFO" - 2:57:47 pm] Formatting completed in 337.6478ms.
2
  • 1
    Are you using some of the newer Apex constructs in the code the formatting fails with? Perhaps the Apex plugin is out-of-date? Or was it the case that the plugin used to format the very same code without issue? Have you considered downgrading to the version you used to use?
    – Phil W
    May 7, 2021 at 6:53
  • 2
    I was only thinking to updating everything I have but downgrading to [email protected] did the trick. Thanks @Phil W.
    – Naga
    May 10, 2021 at 23:00

1 Answer 1

6

Posting this so others can find it useful:

If you run into this error, make sure to update your java version to at least 11 as prettier-plugin-apex version 1.9.0 and above doesn't support for jdk versions below 11.

enter image description here

If you don't want to update java version, downgrade prettier-plugin-apex version to 1.8.0 or below(npm install --save-dev [email protected]).

For more details: https://github.com/dangmai/prettier-plugin-apex/issues/392

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .