Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
OmerMessing opened this issue Jul 10, 2023 · 24 comments · Fixed by econia-labs/econia#341
Closed

Comments

@OmerMessing
Copy link

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
Copy link

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

@jwoLondon
Copy link

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

@GongT
Copy link

GongT commented Jul 13, 2023

0.9.18 works for me, 0.9.19 not.

Why: f6ff18b

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

@francoism90
Copy link

Confirmation here

@azat-io
Copy link

azat-io commented Jul 16, 2023

Same problem and has been for a very long time

@basicdays
Copy link

basicdays commented Jul 17, 2023

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

@imdavidmin
Copy link

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

@hymair
Copy link

hymair commented Jul 21, 2023

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

@Vannsl
Copy link

Vannsl commented Jul 24, 2023

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.

@azat-io
Copy link

azat-io commented Jul 24, 2023

Prettier hasn't worked for over a month now

@MartinSoto
Copy link

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
Copy link

dheeraj-jn commented Aug 16, 2023

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
Copy link

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

@nichtsam
Copy link

nichtsam commented Sep 3, 2023

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

@kitsunekyo
Copy link

kitsunekyo commented Sep 5, 2023

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
Copy link

The same problem

@francoism90
Copy link

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
Copy link

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. 🙏

Copy link

github-actions bot commented Dec 8, 2023

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

@github-actions github-actions bot added the Stale label Dec 8, 2023
@SeriousPickleball
Copy link

SeriousPickleball commented Dec 8, 2023 via email

@ntubrian
Copy link

ntubrian commented Feb 2, 2024

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
Copy link

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

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

Copy link

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

@github-actions github-actions bot added the Stale label Apr 29, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 6, 2024
@martianyi
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.