dangmai / prettier-plugin-apex

Code formatter for the Apex Programming Language
https://apex.dangmai.net
MIT License
235 stars 43 forks source link

Error formatting document at Object.spawnSync (node:internal/child_process:1124:20) #1532

Closed gdlt88 closed 2 months ago

gdlt88 commented 2 months ago

Self-Troubleshooting Checklist

Describe your issue

When trying to format documents using prettier-plugin-apex in VS code in my Windows 10, I'm receiving the following error message

["ERROR" - 12:33:14 PM] Error formatting document.
Error: spawnSync C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier-plugin-apex\vendor\apex-ast-serializer\bin\apex-ast-serializer.bat EINVAL
    at Object.spawnSync (node:internal/child_process:1124:20)
    at spawnSync (node:child_process:914:24)
    at parseTextWithSpawn (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier-plugin-apex\src\parser.ts:37:36)
    at Object.parse (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier-plugin-apex\src\parser.ts:589:21)
    at Object.parse (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier\index.js:7334:23)
    at coreFormat (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier\index.js:8645:18)
    at formatWithCursor2 (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier\index.js:8837:18)
    at C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier\index.js:37229:12
    at Object.format (C:\Users\la170\OneDrive\Documentos\Github\salesforce-crm\node_modules\prettier\index.js:37243:12)
    at t.PrettierMainThreadInstance.format (c:\Users\la170\.vscode\extensions\esbenp.prettier-vscode-10.1.0\dist\extension.js:1:18023)
    at t.default.format (c:\Users\la170\.vscode\extensions\esbenp.prettier-vscode-10.1.0\dist\extension.js:1:16114)
    at t.PrettierEditProvider.provideEdits (c:\Users\la170\.vscode\extensions\esbenp.prettier-vscode-10.1.0\dist\extension.js:1:12672)
    at W.provideDocumentFormattingEdits (c:\Users\la170\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:154:109702)

I have the following configuration:

I've tried:

Prettier options (if any)

{
  "trailingComma": "none",
  "overrides": [
    {
      "files": "sumoCustomCode/headCode.js",
      "options": {"singleQuote": true}
    },
    {
      "files": "**/lwc/**/*.html",
      "options": { "parser": "lwc" }
    },
    {
      "files": "*.{cmp,page,component}",
      "options": { "parser": "html" }
    },
    {
      "files": "{data,seeds}/**/*.cls",
      "options": { "parser": "apex-anonymous" }
    }
  ],
  "printWidth": 120
}

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (16) x64 AMD Ryzen 9 5900HS with Radeon Graphics
    Memory: 11.83 GB / 31.41 GB
  Binaries:
    Node: 19.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 9.6.3 - C:\Program Files\nodejs\npm.CMD
  Languages:
    Bash: 4.4.23 - C:\Users\la170\OneDrive\Documentos\installers\git-sdk-64-main\usr\bin\bash.EXE
    Java: 11.0.6 - C:\Program Files\Java\jdk-11.0.6\bin\javac.EXE
    Perl: 5.34.0 - C:\Users\la170\OneDrive\Documentos\installers\git-sdk-64-main\usr\bin\perl.EXE
    Python: 3.9.10 - C:\Users\la170\OneDrive\Documentos\installers\git-sdk-64-main\mingw64\bin\python.EXE
    Python3: 3.9.10 - C:\Users\la170\OneDrive\Documentos\installers\git-sdk-64-main\mingw64\bin\python3.EXE
    Ruby: 3.0.3 - C:\Users\la170\OneDrive\Documentos\installers\git-sdk-64-main\mingw64\bin\ruby.EXE
    Rust: 1.77.0 - C:\Users\la170\.cargo\bin\rustc.EXE
  npmPackages:
    prettier: 2.7.1 => 2.7.1
    prettier-plugin-apex: ^1.10.0 => 1.13.0
dangmai commented 2 months ago

Hello, this is because you're running a very old version of Prettier Apex (recent versions of NodeJS on Windows has some breaking changes that need changes on the library side). Please upgrade to the latest version using this guide: https://github.com/dangmai/prettier-plugin-apex/wiki/Upgrading-to-Prettier-Apex-v2