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

9.19.0 fails to load from custom prettierPath #3059

Closed
whoisarpit opened this issue Jul 3, 2023 · 7 comments
Closed

9.19.0 fails to load from custom prettierPath #3059

whoisarpit opened this issue Jul 3, 2023 · 7 comments
Labels
locked Please open a new issue and fill out the template instead of commenting. Stale

Comments

@whoisarpit
Copy link

Summary

#3041 is recurring because of f6ff18b

Quoting #3041 below:

In 9.16, when configured with a path to the prettier module (eg. node_modules/prettier), the extension fails to load.

Steps To Reproduce:

Set prettier.prettierPath config to node_modules/prettier

Expected result

Extension loads node_modules/prettier/package.json successfully.

Actual result

Extension fails to load. The extension appears to look for node_modules/packages.json, then package.json, etc.

Additional information

VS Code Version: 1.79.2

Prettier Extension Version: 9.16

OS and version: Mac OS Ventura 13.4

Prettier Log Output

Below trace is from #3038 (comment). cc @mreduar

["INFO" - 1:39:28 PM] Extension Name: esbenp.prettier-vscode.
["INFO" - 1:39:28 PM] Extension Version: 9.16.0.
["INFO" - 1:39:28 PM] Attempted to load Prettier module from /var/www/html/node_modules/prettier
["ERROR" - 1:39:28 PM] Failed to load module. If you have prettier or plugins referenced in package.json, ensure you have run `npm install`
["ERROR" - 1:39:28 PM] Cannot load Prettier version from package.json
Error: Cannot load Prettier version from package.json
    at t.ModuleResolver.loadPrettierVersionFromPackageJson (/root/.vscode-server/extensions/esbenp.prettier-vscode-9.16.0/dist/extension.js:1:3820)
    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)
@AndrewKvalheim
Copy link

A workaround has been shared at #3100 (comment).

@trevorr
Copy link

trevorr commented Sep 15, 2023

I believe this issue is a regression caused by f6ff18b, which was an attempt to fix #3045.

I added a bit of logging to the module resolution to show what's happening:

["DEBUG" - 10:16:41 PM] Local prettier module path: '/Users/trevor/git/my_project/node_modules/prettier'
["INFO" - 10:16:41 PM] loadPrettierVersionFromPackageJson: /Users/trevor/git/my_project/node_modules/prettier
["INFO" - 10:16:41 PM] pkgFilePath: /Users/trevor/git/my_project/node_modules/package.json
["INFO" - 10:16:41 PM] pkgFilePath: /Users/trevor/git/my_project/package.json
["INFO" - 10:16:41 PM] Loaded /Users/trevor/git/my_project/package.json

Basically, loadPrettierVersionFromPackageJson was changed to search for the module with cwd set to the parent of the module path, rather than the module path itself. This causes it to read the package.json of the containing project rather than the one for prettier. In my monorepo project, there is no version in the root package.json, which causes the error above.

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 Nov 15, 2023
@fat0troll
Copy link

This issue is still exist in latest version of VS Code and this extension.

@github-actions github-actions bot removed the Stale label Nov 17, 2023
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 Jan 16, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
@nimish-gupta
Copy link

This issue still exist in the latest version, any temp solution for this?

Copy link

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 github-actions bot added the locked Please open a new issue and fill out the template instead of commenting. label May 16, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked Please open a new issue and fill out the template instead of commenting. Stale
Projects
None yet
Development

No branches or pull requests

5 participants