prettier-vscode icon indicating copy to clipboard operation
prettier-vscode copied to clipboard

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

Open OmerMessing opened this issue 2 years ago • 23 comments

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.

OmerMessing avatar Jul 10 '23 08:07 OmerMessing

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

ahmadx16 avatar Jul 12 '23 05:07 ahmadx16

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

jwoLondon avatar Jul 13 '23 10:07 jwoLondon

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

GongT avatar Jul 13 '23 12:07 GongT

Confirmation here

francoism90 avatar Jul 13 '23 19:07 francoism90

Same problem and has been for a very long time

azat-io avatar Jul 16 '23 10:07 azat-io

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:

  • MacOS 12.6.7
  • NodeJS 18.15.0
  • Prettier 2.8.4
  • VSCode 1.80.1

basicdays avatar Jul 17 '23 16:07 basicdays

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

imdavidmin avatar Jul 20 '23 15:07 imdavidmin

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

  • MacOS: latest
  • Node: 18
  • Prettier: 3.x

hymair avatar Jul 21 '23 05:07 hymair

Same issue.

  • MacOS: Ventura 13.0
  • Node: 18.16.1
  • Prettier: 3.x
["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.

Vannsl avatar Jul 24 '23 15:07 Vannsl

Prettier hasn't worked for over a month now

azat-io avatar Jul 24 '23 16:07 azat-io

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.

MartinSoto avatar Jul 27 '23 22:07 MartinSoto

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.

dheeraj-jn avatar Aug 16 '23 07:08 dheeraj-jn

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

ssbarnea avatar Aug 31 '23 17:08 ssbarnea

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

nichtsam avatar Sep 03 '23 11:09 nichtsam

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

kitsunekyo avatar Sep 05 '23 08:09 kitsunekyo

The same problem

KevinYouu avatar Sep 05 '23 11:09 KevinYouu

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.

francoism90 avatar Sep 05 '23 12:09 francoism90

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:

lobo-tuerto avatar Sep 05 '23 23:09 lobo-tuerto

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

github-actions[bot] avatar Dec 08 '23 01:12 github-actions[bot]

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: @.***>

SeriousPickleball avatar Dec 08 '23 19:12 SeriousPickleball

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!!

ntubrian avatar Feb 02 '24 06:02 ntubrian

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

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

oriolgual avatar Feb 14 '24 10:02 oriolgual

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

github-actions[bot] avatar Apr 29 '24 01:04 github-actions[bot]

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.

martianyi avatar May 13 '24 12:05 martianyi

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Aug 12 '24 00:08 github-actions[bot]