stylelint / vscode-stylelint

The official Visual Studio Code extension for Stylelint
https://marketplace.visualstudio.com/items?itemName=stylelint.vscode-stylelint
MIT License
318 stars 31 forks source link

[Bug]: Prettier plugins cannot be resolved when package.json is not in the root folder #470

Open grofzero opened 1 year ago

grofzero commented 1 year ago

How did you encounter this bug?

I have a project in the frontend folder which is not the root of the project. I use vue, prettier and pug. I use @prettier/plugin-pug to format pug. So my prettier config looks like this:

{ "plugins": ["@prettier/plugin-pug"], "printWidth": 120, "pugPrintWidth": 500, "pugUseTabs": true, "singleQuote": true, "pugSingleQuote": false, "semi": true, "useTabs": true, "tabWidth": 4, "endOfLine": "auto", "trailingComma": "none" }

I use 'stylelint-prettier' to format the css parts with prettier.

When I try to format an scss file with vs code it show an error "Error: Cannot find package '@prettier/plugin-pug'"

When I run stylelint from my frontend folder it runs fine.

Link to Minimal Reproducible Example

https://github.com/grofzero/stylelint-prettier-test

Code Snippet

No response

Stylelint Configuration

{
    "extends": [
        "stylelint-config-standard-scss", "stylelint-config-recommended-vue/scss"
    ],
    "plugins": [
        "stylelint-prettier"
    ],
    "overrides": [
        {
          "files": [
                "**/*.scss", "**/*.vue"
            ]
        }
    ],
    "rules": {
        "prettier/prettier": true,
        "max-nesting-depth": 4,
        "at-rule-no-unknown": null
    }
}

Extension Configuration

No response

Actual Behaviour

Error: Cannot find package '@prettier/plugin-pug

Expected Behaviour

To format the scss.

Logs

Error: Cannot find package '@prettier/plugin-pug' imported from /home/kornel/workspace-mt/stylelint-prettier-test/noop.js at new NodeError (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:18797:5) at packageResolve (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:19742:9) at moduleResolve (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:19774:20) at defaultResolve (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:19879:15) at resolve (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:19897:12) at importFromFile (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:19912:15) at importFromDirectory (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:20181:10) at file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:20198:12 at async loadPlugin (file:///home/kornel/workspace-mt/stylelint-prettier-test/frontend/node_modules/prettier/index.mjs:20203:28) at async Promise.all (index 0)

Stylelint Version

15.10.3

vscode-stylelint Version

1.2.4

Node.js Version

v18.14.0

Operating System

Ubuntu 22.04.3 LTS

Windows Subsystem for Linux

No response

Code of Conduct

DariushStony commented 7 months ago

I have the same issue