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

Plugin settings are not recognized #2429

Closed
logue opened this issue Feb 15, 2022 · 11 comments
Closed

Plugin settings are not recognized #2429

logue opened this issue Feb 15, 2022 · 11 comments
Labels
locked Please open a new issue and fill out the template instead of commenting.

Comments

@logue
Copy link

logue commented Feb 15, 2022

Summary

All plugins for Prettier are not recognized by vscode prettier and I get a Cannot find module error.

Github Repository to Reproduce Issue

https://github.com/logue/vite-vue2-ts-starter

Currently, this issue intentionally comments out the plugin settings.

Steps To Reproduce:

  1. Install the plugin for any pretter in your project.
  2. Fill in the prettierrc plugins with any plugins you have installed.

The settings in .prettierrc.yml are as follows:

printWidth: 80
tabWidth: 2
useTabs: false
semi: true
singleQuote: true
trailingComma: es5
bracketSpacing: true
bracketSameLine: false
arrowParens: avoid
htmlWhitespaceSensitivity: ignore
endOfLine: lf
plugins:
  - prettier-plugin-jsdoc
  - prettier-plugin-md-nocjsp
  - prettier-plugin-sort-imports

Expected result

The plugin settings are also reflected in prettier-vscode, and formatting is performed based on it.

Actual result

When the plugin is configured, its contents are not recognized and the error Cannot find module is raised.

It does not occur if you comment out all the plugin lines.

Additional information

I have confirmed that running prettier directly from the command line in the project root works without problems.

VS Code Version:

バージョン: 1.64.2 (system setup)
コミット: f80445acd5a3dadef24aa209168452a3d97cc326
 日付: 2022-02-09T22:02:28.252Z
Electron: 13.5.2
Chromium: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.22000

Prettier Extension Version:

9.2.0

OS and version:

Windows 11

Prettier Log Output

["INFO" - 16:54:00] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 16:54:00] Prettier Options:
{
  "filepath": "[PROJECT DIRECTORY]\\.prettierrc.yml",
  "parser": "yaml",
  "useTabs": false,
  "tabWidth": 2,
  "endOfLine": "lf",
  "printWidth": 80,
  "semi": true,
  "singleQuote": true,
  "trailingComma": "es5",
  "bracketSpacing": true,
  "bracketSameLine": false,
  "arrowParens": "avoid",
  "htmlWhitespaceSensitivity": "ignore",
  "plugins": [
    "prettier-plugin-jsdoc",
    "prettier-plugin-md-nocjsp",
    "prettier-plugin-sort-imports"
  ]
}
["ERROR" - 16:54:00] Error formatting document.
["ERROR" - 16:54:00] Cannot find module 'prettier-plugin-jsdoc'
Require stack:
- [PROJECT DIRECTORY]\node_modules\prettier\index.js
- c:\Users\[USER NAME]\.vscode\extensions\esbenp.prettier-vscode-9.2.0\dist\extension.js
- c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-fork.js
Error: Cannot find module 'prettier-plugin-jsdoc'
Require stack:
- [PROJECT DIRECTORY]\node_modules\prettier\index.js
- c:\Users\[USER NAME]\.vscode\extensions\esbenp.prettier-vscode-9.2.0\dist\extension.js
- c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-amd.js
- c:\Program Files\Microsoft VS Code\resources\app\out\bootstrap-fork.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:934:15)
    at h.resolve (c:\Program Files\Microsoft VS Code\resources\app\out\vs\loader.js:4:761)
    at [PROJECT DIRECTORY]\node_modules\prettier\index.js:60885:21
    at Array.map (<anonymous>)
    at Object.load ([PROJECT DIRECTORY]\node_modules\prettier\index.js:60877:61)
    at Object.load [as loadPlugins] ([Path to Project Directory]\node_modules\prettier\index.js:16258:23)
    at [PROJECT DIRECTORY]\node_modules\prettier\index.js:60957:24
    at Object.Success [as format] ([Path to Project Directory]\node_modules\prettier\index.js:60979:12)
    at t.default.format (c:\Users\[USER NAME]\.vscode\extensions\esbenp.prettier-vscode-9.2.0\src\PrettierEditService.ts:435:45)
    at t.PrettierEditProvider.provideEdits (c:\Users\[USER NAME]\.vscode\extensions\esbenp.prettier-vscode-9.2.0\src\PrettierEditService.ts:322:22)
    at g.provideDocumentFormattingEdits (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:93:98509)
["INFO" - 16:54:00] Formatting completed in 0.008ms.
@benallfree
Copy link

Having a similar problem with @prettier/plugin-php. Runs fine from CLI, but vscode plugin doesn't pick it up.

@KillDozerX2
Copy link

The vscode extension has been having issues with applying plugins to prettier.

@ruffin--
Copy link

ruffin-- commented Mar 28, 2022

It seems (for me) to only be looking in the root folder of the workspace. If it's further up or down the folder hierarchy towards the file being prettier-ed, it isn't found.

https://prettier.io/docs/en/configuration.html

The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.

Same issue with .prettierignore

@JounQin
Copy link
Member

JounQin commented Jun 29, 2022

And this mostly can be, you've installed multiple prettier versions locally, you can check your lock files to ensure, and you can always use plugins: [require('pkg')] instead relying on prettier's auto-check.

Take https://github.com/1stG/configs/blob/master/packages/prettier-config/base.js base an example.

@JounQin
Copy link
Member

JounQin commented Jun 29, 2022

See also prettier/prettier#8474, not exactly the same, but related, multiple prettier versions or plugin-* unreachable.

@JounQin
Copy link
Member

JounQin commented Jun 29, 2022

@logue
Copy link
Author

logue commented Jun 29, 2022

Then, is it solved by writing in package.json like the following?

  "resolutions": {
    "eslint-plugin-prettier": "^4.1.0",
    "prettier": "^2.7.1"
  }

@JounQin
Copy link
Member

JounQin commented Jun 29, 2022

@logue

A single "prettier": "^2.7.1" would work, but [email protected] is preferred to be installed because of its new feature.

logue added a commit to logue/vite-vue2-ts-starter that referenced this issue Jun 29, 2022
… issue that was causing potential glitches. (prettier/prettier-vscode#2429)

Update Dependencies.
logue added a commit to logue/vite-vue2-vuetify-ts-starter that referenced this issue Jun 29, 2022
Fixed Prettier having multiple versions installed due to a dependency issue that was causing potential glitches. (prettier/prettier-vscode#2429)
Update Dependencies.
@JounQin
Copy link
Member

JounQin commented Jul 1, 2022

@logue I think this can be closed then?

@logue
Copy link
Author

logue commented Jul 1, 2022

OK

@logue logue closed this as completed Jul 1, 2022
@github-actions
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 Sep 30, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2022
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.
Projects
None yet
Development

No branches or pull requests

5 participants