Open test01bodacious opened 3 weeks ago
Parser of type apex
does not exist. Here is a .prettierrc
we are using which formats the apex files just fine.
{
"trailingComma": "none",
"singleQuote": true,
"tabWidth": 4,
"printWidth": 150,
"plugins": [
"prettier-plugin-apex",
"@prettier/plugin-xml"
],
"overrides": [
{
"files": "**/lwc/**/*.html",
"options": {
"parser": "lwc"
}
},
{
"files": "*.{cmp,page,component}",
"options": {
"parser": "html"
}
}
]
}
with this part of package.json
"devDependencies": {
"@prettier/plugin-xml": "^3.4.1",
"prettier": "^3.3.3",
"prettier-plugin-apex": "^2.1.4"
},
I am using the following settings and it's not formatting .cls apex class files and giving the error "Couldn't resolve parser "apex""
Logs: ["INFO" - 2:08:41 AM] Formatting file:///c%3A/Users/myusername/Desktop/Workspace/VS%20Code/DevEdProj1/force-app/main/default/classes/Demo1.cls ["DEBUG" - 2:08:41 AM] Local prettier module path: C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier ["DEBUG" - 2:08:41 AM] Using prettier version 3.3.3 ["INFO" - 2:08:41 AM] Using config file at C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier-plugin-apex\node_modules\wait-on.prettierrc.js ["DEBUG" - 2:08:41 AM] Local prettier module path: C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier ["INFO" - 2:08:41 AM] PrettierInstance: { "modulePath": "C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier", "messageResolvers": {}, "version": "3.3.3" } ["INFO" - 2:08:41 AM] Using ignore file (if present) at c:\Users\myusername\Desktop\Workspace\VS Code\DevEdProj1.prettierignore ["INFO" - 2:08:41 AM] File Info: { "ignored": false, "inferredParser": "apex" } ["INFO" - 2:08:41 AM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used ["INFO" - 2:08:41 AM] Prettier Options: { "filepath": "c:\Users\myusername\Desktop\Workspace\VS Code\DevEdProj1\force-app\main\default\classes\Demo1.cls", "parser": "apex", "tabWidth": 4, "singleQuote": true, "printWidth": 150, "trailingComma": "none" } ["ERROR" - 2:08:41 AM] Error formatting document. ["ERROR" - 2:08:41 AM] Couldn't resolve parser "apex". ConfigError: Couldn't resolve parser "apex". at getParserPluginByParserName (file:///C:/Users/myusername/AppData/Roaming/nvm/v20.18.0/node_modules/prettier/index.mjs:20571:9) at normalizeFormatOptions (file:///C:/Users/myusername/AppData/Roaming/nvm/v20.18.0/node_modules/prettier/index.mjs:20645:24) at formatWithCursor (file:///C:/Users/myusername/AppData/Roaming/nvm/v20.18.0/node_modules/prettier/index.mjs:21333:52) at file:///C:/Users/myusername/AppData/Roaming/nvm/v20.18.0/node_modules/prettier/index.mjs:22728:12 at async Module.format2 (file:///C:/Users/myusername/AppData/Roaming/nvm/v20.18.0/node_modules/prettier/index.mjs:22733:25) ["INFO" - 2:08:41 AM] Formatting completed in 16ms.
My settings:
I have installed plugin globally
node version: v20.18.0 (latest LTS) prettier version: 3.3.3 prettier-plugin-apex version: 2.1.5 @prettier/plugin-xml version: 3.4.1
Java version: java 17.0.4.1 2022-08-18 LTS (VS Code Java Home path configured)
VS Code Extension "Prettier - Code formatter" version: v11.0.0
Using Using native executables: npx install-apex-executables
.prettierrc.js Path: "C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier-plugin-apex\node_modules\wait-on.prettierrc.js"
.prettierrc.js File module.exports = { tabWidth: 4, singleQuote: true, printWidth: 150, trailingComma: "none", //plugins: ["prettier-plugin-apex", "@prettier/plugin-xml"], overrides: [{ files: "/lwc//*.html", options: { parser: "lwc", tabWidth: 4 } }, { files: "*/.{cls,trigger}", options: { parser: "apex", apexInsertFinalNewline: true, printWidth: 150, tabWidth: 4 } }, { files: "*/.{apex}", options: { parser: "apex-anonymous", apexInsertFinalNewline: true, printWidth: 150, tabWidth: 4 } }, { files: "*.{cmp,page,component}", options: { parser: "html", tabWidth: 4 } } ] };
Note: I had to comment //plugins: ["prettier-plugin-apex", "@prettier/plugin-xml"] as it is giving error: Unable to resolve "prettier-plugin-apex"
package.json
{ "name": "salesforce-app", "private": true, "version": "1.0.0", "description": "Salesforce App", "scripts": { "lint": "eslint /{aura,lwc}//*.js", "test": "npm run test:unit", "test:unit": "sfdx-lwc-jest", "test:unit:watch": "sfdx-lwc-jest --watch", "test:unit:debug": "sfdx-lwc-jest --debug", "test:unit:coverage": "sfdx-lwc-jest --coverage", "prettier": "prettier --apex-standalone-parser native --write \"/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"", "prettier:verify": "prettier --apex-standalone-parser nativex --check \"*/.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}\"", "postinstall": "husky install", "precommit": "lint-staged" }, "devDependencies": { "@lwc/eslint-plugin-lwc": "^1.1.2", "@prettier/plugin-xml": "3.4.1", "@salesforce/eslint-config-lwc": "^3.2.3", "@salesforce/eslint-plugin-aura": "^2.0.0", "@salesforce/eslint-plugin-lightning": "^1.0.0", "@salesforce/sfdx-lwc-jest": "^5.1.0", "eslint": "^9.9.1", "eslint-plugin-import": "^2.25.4", "eslint-plugin-jest": "^28.8.1", "husky": "^9.1.5", "lint-staged": "^15.1.0", "prettier": "3.3.3", "prettier-plugin-apex": "2.1.5" }, "lint-staged": { "/.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}": [ "prettier --apex-standalone-parser native --write" ], "/{aura,lwc}//.js": [ "eslint" ] } }
VS Code Settings:
Prettier: Config Path C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier-plugin-apex\node_modules\wait-on.prettierrc.js
Prettier: Prettier Path C:\Users\myusername\AppData\Roaming\nvm\v20.18.0\node_modules\prettier