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

Regression on package.json finding behavior for globally installed prettier with vscode extension #3045

Closed wxf-contentgroove closed 10 months ago

wxf-contentgroove commented 10 months ago

Summary

The prettier vscode extension seems to have had a behavior regression in version 9.16.0. It is no longer able to load the package.json for a globally installed prettier on macOS

Steps To Reproduce:

  1. Set prettier path to the globally installed version of prettier, typically: /usr/local/lib/node_modules/prettier on macOS
  2. Try to format a file with the "Format document" command

Expected result

The file is formatted with prettier

Actual result

The document is not formatted and the prettier extension throws an error.

Additional information

Behavior works as expected on extension version 9.15.0. Additionally, prettier is present in the path and can be run as expected from the command line.

I have not checked if this behavior regression is also present on Windows or Linux.

EDIT: as per this reply to the issue, it appears to also effect windows

Here's the ls of the prettier install location ( /usr/local/lib/node_modules/prettier )

➜  ~ ls  /usr/local/lib/node_modules/prettier
LICENSE              parser-angular.js    parser-meriyah.js
README.md            parser-babel.js      parser-postcss.js
bin-prettier.js      parser-espree.js     parser-typescript.js
cli.js               parser-flow.js       parser-yaml.js
doc.js               parser-glimmer.js    standalone.js
esm                  parser-graphql.js    third-party.js
index.js             parser-html.js
package.json         parser-markdown.js

All the correct files appear to be present

VS Code Version:

Version: 1.77.3 Commit: 704ed70d4fd1c6bd6342c436f1ede30d1cff4710 Date: 2023-04-12T09:19:37.325Z (2 mos ago) Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Darwin x64 22.3.0 Sandboxed: No

Prettier Extension Version:

v9.16.0

OS and version: macOS Ventura Version 13.2.1 (22D68)

Prettier Log Output

["DEBUG" - 3:22:59 PM] Local prettier module path: '/usr/local/lib/node_modules/prettier'
["INFO" - 3:22:59 PM] Attempted to load Prettier module from /usr/local/lib/node_modules/prettier
["ERROR" - 3:22:59 PM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 3:22:59 PM] Cannot find Prettier package.json
Error: Cannot find Prettier package.json
    at t.ModuleResolver.loadPrettierVersionFromPackageJson (/Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:3693)
    at t.ModuleResolver.getPrettierInstance (/Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:5087)
    at t.default.handleActiveTextEditorChanged (/Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:10688)
    at t.default.handleActiveTextEditorChangedSync (/Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:10290)
    at t.default.registerDisposables (/Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:13133)
    at /Users/user/.vscode/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:81225
leejanmorado commented 10 months ago

experiencing this even on local installation

PawelBorys commented 10 months ago

I am experiencing the same issue on Windows with globally installed prettier

Version: 1.79.2 (user setup) Commit: 695af097c7bd098fbf017ce3ac85e09bbc5dda06 Date: (2 wks ago) Electron: 22.5.7 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows NT x64 10.0.22621

Prettier version v9.16.0

["INFO" - 1:35:15 PM] Attempted to load Prettier module from C:\Users\***\AppData\Roaming\npm\node_modules\prettier
["ERROR" - 1:35:15 PM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 1:35:15 PM] Cannot find Prettier package.json
Error: Cannot find Prettier package.json
    at t.ModuleResolver.loadPrettierVersionFromPackageJson (c:\Users\***\.vscode\extensions\esbenp.prettier-vscode-9.16.0\dist\extension.js:1:3693)
    at t.ModuleResolver.getPrettierInstance (c:\Users\***\.vscode\extensions\esbenp.prettier-vscode-9.16.0\dist\extension.js:1:5087)
    at t.default.format (c:\Users\***\.vscode\extensions\esbenp.prettier-vscode-9.16.0\dist\extension.js:1:14402)
    at async t.PrettierEditProvider.provideEdits (c:\Users\***\.vscode\extensions\esbenp.prettier-vscode-9.16.0\dist\extension.js:1:12274)
    at async U.provideDocumentFormattingEdits (c:\Users\***\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:101:45790)
wxf-contentgroove commented 10 months ago

I think this might be the change that broke it: https://github.com/prettier/prettier-vscode/commit/d04b294a15f9dc20e1dc061013b57c7aa8f2764c

hediet commented 10 months ago

It also broke for me in 9.16 with the same error message (windows). 9.15 works.

ntotten commented 10 months ago

The change https://github.com/prettier/prettier-vscode/commit/d04b294a15f9dc20e1dc061013b57c7aa8f2764c from 9.16 was reverted. 9.19 is rolling out now. Thanks for reporting.

garyking commented 10 months ago

9.19 is still broken. 9.15 is still good.

leejanmorado commented 10 months ago

Still broken

wxf-contentgroove commented 10 months ago

@ntotten Appears to still be broken on 9.19, requesting re-open of the issue. Just tested. and it's throwing the same error.

93Akkord commented 10 months ago

@ntotten Appears to still be broken on 9.19, requesting re-open of the issue. Just tested. and it's throwing the same error.

Yes, same here. Still broken.

azat-io commented 10 months ago

@ntotten Can you reopen the issue?

Yossri21 commented 10 months ago

still broken!

HakobjanianDavid commented 10 months ago

Workaround: just return to previous version by VSIX example for python-ext

vsiao commented 10 months ago

@wxf-contentgroove:

I think this might be the change that broke it: d04b294

This issue is a duplicate of #3041, which that commit was supposed to fix. @ntotten can you unrevert d04b294 and fix this issue and #3059?

In the meantime, users should try manually installing v9.18.0.

livevie commented 9 months ago

is it now working for anyone? i still can't use it

azat-io commented 9 months ago

@ntotten Please reopen this issue

paulalbertdev commented 9 months ago

Same pb here

carlosmrivera commented 9 months ago

I'm facing this issue on v10.1.0

paulalbertdev commented 9 months ago

This seems to do the trick : https://github.com/prettier/prettier-vscode/issues/3100#issuecomment-1666476812

oliver841025 commented 9 months ago

same pb here

paulshestakov commented 9 months ago

same problem

ddlaat commented 9 months ago

same problem

kachkaev commented 9 months ago

Folks, please use 👍 reaction instead of ‘+1 comments’. The latter clutter Notifications for other devs and don’t any value.

ShlokDesai33 commented 8 months ago

Please reopen this issue.

madaxen86 commented 7 months ago

This did the trick for me:

-"prettier.prettierPath": "./packages/compiler/node_modules/prettier",
+"prettier.prettierPath": "./packages/compiler/node_modules/prettier/index.cjs",
lazuee commented 7 months ago

@madaxen86 thanks, it works.


{
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.formatOnPaste": true,
"prettier.enable": true,
"prettier.withNodeModules": true,
"prettier.requireConfig": false,
# using nodejs-lts from scoop
"prettier.prettierPath": "C:/Users/Admin/scoop/persist/nodejs-lts/bin/node_modules/prettier/index.cjs",
}
izeau commented 5 months ago

For fnm users:

{
  "prettier.prettierPath": "~/.fnm/aliases/default/lib/node_modules/prettier/index.cjs"
}
github-actions[bot] commented 2 months ago

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.