prettier / prettier-vscode

Visual Studio Code extension for Prettier
https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
MIT License
5.04k stars 446 forks source link

Prettier does not format documents in latest Prettier + VS code versions #3071

Closed OmerMessing closed 1 week ago

OmerMessing commented 10 months ago

Summary

Prettier does not format code, error and logs shown below.

Using: Ubuntu: 22.04.2 in Windows + WSL 2 VS Code: 1.80.0 Prettier: 9.19.0

Github Repository to Reproduce Issue

Installed the latest prettier vs-code extension.

Steps To Reproduce:

  1. Install al the latest versions of the software I listed.
  2. CTRL+SHIFT+P and choose Format Document (with prettier) \ or any other way to format the document
  3. Document is not being formatted

Expected result

Document should be formatted.

Actual result

Document is not formatted.

Additional information

I updated to the latest prettier extension + regular vs code update and it just stopped working.

VS Code Version:

Version: 1.80.0 (user setup) Commit: 660393deaaa6d1996740ff4880f1bad43768c814 Date: 2023-07-04T15:06:02.407Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19044

Prettier Extension Version:

Prettier: 9.19.0

OS and version:

Windows 10 Pro Version 21H2

Prettier Log Output


["INFO" - 10:51:46 AM] Formatting file:///..........(path was removed from log)
["INFO" - 10:51:46 AM] Attempted to load Prettier module from /usr/lib/node_modules/prettier
["ERROR" - 10:51:46 AM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 10:51:46 AM] Cannot find Prettier package.json
Error: Cannot find Prettier package.json
    at t.ModuleResolver.loadPrettierVersionFromPackageJson (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:3996)
    at t.ModuleResolver.getPrettierInstance (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:5305)
    at t.ModuleResolver.getResolvedConfig (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:7434)
    at t.default.format (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:14527)
    at t.PrettierEditProvider.provideEdits (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:12621)
    at t.PrettierEditProvider.provideDocumentFormattingEdits (/home/omer/.vscode-server/extensions/esbenp.prettier-vscode-9.19.0/dist/extension.js:1:8860)
    at O.provideDocumentFormattingEdits (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:102:45061)
    at /home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:102:67984
    at se.s (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:102:62833)
    at se.$provideDocumentFormattingEdits (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:102:67971)
    at t.N (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:112:11199)
    at t.M (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:112:10965)
    at t.H (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:112:10007)
    at t.G (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:112:9122)
    at i.value (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:112:7952)
    at p.w (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:1902)
    at p.fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:2119)
    at fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:13931)
    at i.value (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:30341)
    at p.w (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:1902)
    at p.fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:2119)
    at fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:13931)
    at s.z (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:16976)
    at i.value (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:15428)
    at p.w (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:1902)
    at p.fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:2119)
    at i.acceptChunk (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:11705)
    at i.value (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:76:10992)
    at p.w (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:1902)
    at p.fire (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:60:2119)
    at p.u (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:19085)
    at p.acceptFrame (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:18891)
    at a.l (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:17524)
    at /home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:14871
    at Socket.r (/home/omer/.vscode-server/bin/660393deaaa6d1996740ff4880f1bad43768c814/out/vs/workbench/api/node/extensionHostProcess.js:128:12785)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
["ERROR" - 10:51:46 AM] Invalid prettier configuration file detected.
["ERROR" - 10:51:46 AM] EISDIR: illegal operation on a directory, read
Error: EISDIR: illegal operation on a directory, read
["ERROR" - 10:51:46 AM] Invalid prettier configuration file detected. See log for details.
ahmadx16 commented 10 months ago

I am getting the same issue. I rollback to the previous version to resolve it for me. Install previous versions

jwoLondon commented 10 months ago

Yes, for me using the MacOS version of VSCode, the last version of prettier that still works was 9.15.0.

GongT commented 10 months ago

0.9.18 works for me, 0.9.19 not.

Why: https://github.com/prettier/prettier-vscode/commit/f6ff18b500858b913ef43dbad73ecbae929c3b27

I revert this (again, in the dist js file) and it works

francoism90 commented 10 months ago

Confirmation here

azat-io commented 10 months ago

Same problem and has been for a very long time

basicdays commented 10 months ago

Just ran into this as well on extension version v9.19.0. Whether or not prettier.prettierPath is set in VSCode's settings.json didn't make a difference. Reverting to v9.18.0 resolved it.

For info:

imdavidmin commented 10 months ago

Seems like even reverting to an older version does not fix prettier not working when installed via Yarn PnP

hymair commented 10 months ago

Same issue. Getting "Invalid prettier configuration file detected." in the log. Works fine with Prettier 2.8.8.

Vannsl commented 9 months ago

Same issue.

["ERROR" - 17:08:46] Invalid prettier configuration file detected.

UPDATE: Resolved. Was because I had a require for a plugin in the config which wasn't valid anymore.

azat-io commented 9 months ago

Prettier hasn't worked for over a month now

MartinSoto commented 9 months ago

Any progress with this issue? I'm also seeing it since about a month ago.

I have the prettier.prettierPath option pointing to the global node_modules as the extension won't otherwise load the globally installed plugins (we're using prettier-plugin-java).

We have many projects that don't use JavaScript and don't contain a node_modules directory.

Downgrading to 9.15.0 will fix the problem. Starting from 9.16.0 the module fails to load with the following messages:

["INFO" - 12:50:47 AM] Extension Name: esbenp.prettier-vscode.
["INFO" - 12:50:47 AM] Extension Version: 9.16.0.
["INFO" - 12:50:47 AM] Attempted to load Prettier module from /usr/lib/node_modules/prettier
["ERROR" - 12:50:47 AM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 12:50:47 AM] Cannot find Prettier package.json
Error: Cannot find Prettier package.json
    at t.ModuleResolver.loadPrettierVersionFromPackageJson (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:3631)
    at t.ModuleResolver.getPrettierInstance (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:5025)
    at t.default.handleActiveTextEditorChanged (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:10626)
    at t.default.handleActiveTextEditorChangedSync (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:10228)
    at t.default.registerDisposables (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:13071)
    at /root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:81163
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

With the newer versions, removing prettier.prettierPath will fix this error, but the Java plugin won't load, no matter what I do.

dheeraj-jn commented 9 months ago

I was having the same issue and had to downgrade to 9.15.0. But this workaround fixed the issue for me (I'm on prettier 2.x) and now I'm able to use the latest plugin version.

ssbarnea commented 8 months ago

Apparently no downgrade will make it work with 3.0.3,...

nichtsam commented 8 months ago

I'm using prettier 3.0.0 and none of the version of prettier-vscode has worked.

kitsunekyo commented 8 months ago

if your config file is named prettier.config.js try renaming it to .prettierrc.cjs

and update the contents to use commonjs (might not even be necessary):

/** @type {import("prettier").Config} */
const config = {
  singleQuote: true,
  trailingComma: "all",
  plugins: ["prettier-plugin-tailwindcss"],
  tailwindConfig: "./tailwind.config.js",
};

module.exports = config;

looks like something with the module type parsing is messed up.

source

KevinYouu commented 8 months ago

The same problem

francoism90 commented 8 months ago

The only 'workaround' for me is running Prettier over CLI before creating a PR:

"scripts": {
        "format": "npx prettier . --write",
    },

It's not a solution whatsoever, it just the only thing I think to get my documents formatted.

lobo-tuerto commented 8 months ago

After updating some dependencies on my project, Prettier stopped formatting .vue files through VSCode.
But it was still running OK from the CLI.

I tried the solution from @kitsunekyo, and found out that this was the line causing the issue:

module.exports = {
  plugins: [require('prettier-plugin-tailwindcss')],
  // ...
}

Changing that to this solved the issue for me:

module.exports = {
  plugins: ['prettier-plugin-tailwindcss'],
  // ...
}

It was logging out Invalid prettier configuration file detected. See log for details..

Everything is good now. :pray:

github-actions[bot] commented 5 months ago

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

SeriousPickleball commented 5 months ago

Still monitoring.

On Thu, Dec 7, 2023 at 8:51 PM github-actions[bot] @.***> wrote:

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

— Reply to this email directly, view it on GitHub https://github.com/prettier/prettier-vscode/issues/3071#issuecomment-1846433127, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBO4GJQXG4UHMFULVR5WKJ3YIJXBLAVCNFSM6AAAAAA2EFESYWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWGQZTGMJSG4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

ntubrian commented 3 months ago

if your config file is named prettier.config.js try renaming it to .prettierrc.cjs

and update the contents to use commonjs (might not even be necessary):

/** @type {import("prettier").Config} */
const config = {
  singleQuote: true,
  trailingComma: "all",
  plugins: ["prettier-plugin-tailwindcss"],
  tailwindConfig: "./tailwind.config.js",
};

module.exports = config;

looks like something with the module type parsing is messed up.

source

this answer saved my life and my job!!

oriolgual commented 3 months ago

What fixed it for me was adding this to VS Code settings:

"prettier.prettierPath": "./node_modules/prettier/index.js"

github-actions[bot] commented 2 weeks ago

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

martianyi commented 5 days ago

I encountered this issue when I synchronized my VSCode settings on another computer; the Prettier extension was referencing a different path. Correcting the 'prettier.prettierPath' setting resolved the problem for me.