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

Vetur cannot use Prettier installed via Yarn Berry (PnP) #2092

Open
3 tasks done
bkarlson opened this issue Jul 31, 2020 · 8 comments
Open
3 tasks done

Vetur cannot use Prettier installed via Yarn Berry (PnP) #2092

bkarlson opened this issue Jul 31, 2020 · 8 comments

Comments

@bkarlson
Copy link

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: MacOS
  • Vetur version: 0.25.0
  • VS Code version: 1.47.2

Problem

I'm using Yarn 2.1.1, and installed Prettier using official manual: https://next.yarnpkg.com/advanced/editor-sdks/

Yarn installs packages within .yarn folder, and Vetur cannot find Prettier in such case:

[Error - 1:00:16 AM] Cannot find module 'prettier' from '/workspace/package.json'

If I unplug the package and move node_modules from .yarn into the workspace root, Vetur works fine.

I assume Vetur is not 100% PnP compatible, at least when it comes to Prettier (maybe some other libs too).

@yoyo930021
Copy link
Member

yoyo930021 commented Aug 1, 2020

Follow up #1711.

@merceyz
Copy link
Contributor

merceyz commented Sep 19, 2020

The fix here, just as with typescript, is to respect the prettier.prettierPath config

@yoyo930021
Copy link
Member

I open a new issue #2469 .
Now the bundled version will be used if prettier can't be found.

@yoyo930021
Copy link
Member

Fixed #2478

@merceyz
Copy link
Contributor

merceyz commented Dec 8, 2020

I did not fix this issue in #2478 , the code that looks for prettier does not use require.resolve so it doesn't work under PnP

@yoyo930021
Copy link
Member

yoyo930021 commented Dec 8, 2020

I did not fix this issue in #2478 , the code that looks for prettier does not use require.resolve so it doesn't work under PnP

The error is solved.

The prettier part write in documention.
https://vuejs.github.io/vetur/guide/setup.html#yarn-pnp

@bkarlson
Copy link
Author

bkarlson commented Jan 5, 2021

@yoyo930021 , I still cannot make Prettier work with Vetur (Prettier works with everything else though):

Prettier format failed
[Error - 9:04:26 PM] Error: Your application tried to access prettier, but it isn't declared in your dependencies; this makes the require call ambiguous and unsound.

Required package: prettier (via "prettier")
Required by: /Volumes/Backup/home/Documents/src/components/My/MyTabs.vue/

Require stack:
- /Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vls.js
- /Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vueServerMain.js
    at internalTools_makeError (/Volumes/Backup/home/Documents/.pnp.js:21850:34)
    at resolveToUnqualified (/Volumes/Backup/home/Documents/.pnp.js:22809:23)
    at resolveRequest (/Volumes/Backup/home/Documents/.pnp.js:22907:29)
    at Object.resolveRequest (/Volumes/Backup/home/Documents/.pnp.js:22985:26)
    at Function.external_module_.Module._resolveFilename (/Volumes/Backup/home/Documents/.pnp.js:22083:34)
    at Function.resolve (internal/modules/cjs/helpers.js:80:19)
    at Object.get (/Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vls.js:576:3728)
    at prettierify (/Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vls.js:577:754)
    at Object.format (/Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vls.js:610:3079)
    at /Volumes/Backup/home/.vscode/extensions/octref.vetur-0.31.3/server/dist/vls.js:866:3932

Tried installing both into root workspace and project workspace, played with "prettier.prettierPath": ".yarn/pnpify/prettier/index.js" and unplugged Prettier -- nothing works with Vetur.

This line from Vetur docs is super ambigious:

Prettier don't support yarn pnp, so can't load plugin automatic.

Does it mean users need to load plugin (which?) manually (how??). Prettier supports pnp afaik, at least it works with other filetypes in VSCode being installed via Yarn 2 w/ pnp (see yarnpkg/berry#1903 (comment))

@yoyo930021
Copy link
Member

I am not familiar with PnP.
If anyone can help, the PR is welcome.

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

No branches or pull requests

3 participants