hugomrdias / prettier-stylelint

code > prettier > stylelint > formatted code
MIT License
175 stars 29 forks source link

Couldn't resolve parser "postcss" when updated prettier to v2.0.4 #50

Open etylsarin opened 4 years ago

etylsarin commented 4 years ago

I use prettier-stylelint to let prettier formart my scss files using my stylelint rules. I have a problem since I upgraded from v 1.19.1 to 2.0.4 I have found that there was a similar issue with prettier-atom while ago: https://github.com/prettier/prettier-atom/issues/388

Environments:

prettier-stylelint --write --quiet 'src/*/.{css,scss}'"

Expected behavior: to pass all the formatting without throwing an error

Actual behavior: I got an error: prettier-stylelint [ERROR]: There was an error formatting "src/index.scss"

Error: Couldn't resolve parser "postcss" at resolveParser (/Users/myname/repos/project/node_modules/prettier/index.js:11341:15) at normalize$1 (/Users/myname/repos/project/node_modules/prettier/index.js:11436:18) at formatWithCursor (/Users/myname/repos/project/node_modules/prettier/index.js:15032:12) at args (/Users/myname/repos/project/node_modules/prettier/index.js:50675:12) at Object.format (/Users/myname/repos/project/node_modules/prettier/index.js:50695:12) at resolveConfig.then/Users/myname/repos/project/node_modules/prettier-stylelint/src/index.js:129:30)

etylsarin commented 4 years ago

A temporary workaround until prettier-stylelint is fixed:

  1. In project root, create patches/prettier-stylelint+0.4.2.patch with contents:
diff --git a/node_modules/prettier-stylelint/src/index.js b/node_modules/prettier-stylelint/src/index.js
index 124c00d..a6f12ec 100644
--- a/node_modules/prettier-stylelint/src/index.js
+++ b/node_modules/prettier-stylelint/src/index.js
@@ -60,7 +60,7 @@ resolveConfig.resolve = (stylelintConfig, prettierOptions = {}) => {
             prettierOptions.tabWidth = indentation;
         }
     }
-    prettierOptions.parser = 'postcss';
+    prettierOptions.parser = 'css';
     debug('prettier %O', prettierOptions);
     debug('linter %O', stylelintConfig);
  1. In package.json, add to scripts:
  "scripts": {
    "postinstall": "patch-package"
  1. yarn add --dev patch-package
  2. yarn install will now patch the package.
binarykitchen commented 4 years ago

It's been months. When is this going to be fixed?

kyrstenkelly commented 4 years ago

+1

agursoyy commented 4 years ago

+1. It has been long time. When is this problem going to be resolved?

lucypoly commented 4 years ago

Hey, anybody?

siiick commented 3 years ago

+1

a-vershinin commented 3 years ago

+1

iMakedonsky commented 3 years ago

+1

vnaik-isc commented 3 years ago

+1

Sebastp commented 3 years ago

Anyone working on it??

AnirudhMergu commented 3 years ago

This is the latest patch, if the above patch doesn't work for you.

diff --git a/node_modules/prettier-stylelint/.editorconfig b/node_modules/prettier-stylelint/.editorconfig
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/.gitattributes b/node_modules/prettier-stylelint/.gitattributes
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/.npmignore b/node_modules/prettier-stylelint/.npmignore
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/.travis.yml b/node_modules/prettier-stylelint/.travis.yml
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/CHANGELOG.md b/node_modules/prettier-stylelint/CHANGELOG.md
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/LICENSE b/node_modules/prettier-stylelint/LICENSE
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/README.md b/node_modules/prettier-stylelint/README.md
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/config.js b/node_modules/prettier-stylelint/config.js
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/fixtures/find-package/deep/style.css b/node_modules/prettier-stylelint/fixtures/find-package/deep/style.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/fixtures/find-package/style.css b/node_modules/prettier-stylelint/fixtures/find-package/style.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/fixtures/less.less b/node_modules/prettier-stylelint/fixtures/less.less
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/fixtures/style.css b/node_modules/prettier-stylelint/fixtures/style.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/index.js b/node_modules/prettier-stylelint/index.js
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/src/cli.js b/node_modules/prettier-stylelint/src/cli.js
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/src/index.js b/node_modules/prettier-stylelint/src/index.js
old mode 100644
new mode 100755
index 124c00d..a6f12ec
--- a/node_modules/prettier-stylelint/src/index.js
+++ b/node_modules/prettier-stylelint/src/index.js
@@ -60,7 +60,7 @@ resolveConfig.resolve = (stylelintConfig, prettierOptions = {}) => {
             prettierOptions.tabWidth = indentation;
         }
     }
-    prettierOptions.parser = 'postcss';
+    prettierOptions.parser = 'css';
     debug('prettier %O', prettierOptions);
     debug('linter %O', stylelintConfig);

diff --git a/node_modules/prettier-stylelint/src/utils.js b/node_modules/prettier-stylelint/src/utils.js
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/test.js b/node_modules/prettier-stylelint/test.js
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/error-after-format.css b/node_modules/prettier-stylelint/tests/error-after-format.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/error-syntax.css b/node_modules/prettier-stylelint/tests/error-syntax.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/less.less b/node_modules/prettier-stylelint/tests/less.less
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/nestes.css b/node_modules/prettier-stylelint/tests/nestes.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/rules/color-no-invalid-hex.css b/node_modules/prettier-stylelint/tests/rules/color-no-invalid-hex.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/tests/test-disable-rules.css b/node_modules/prettier-stylelint/tests/test-disable-rules.css
old mode 100644
new mode 100755
diff --git a/node_modules/prettier-stylelint/yarn.lock b/node_modules/prettier-stylelint/yarn.lock
old mode 100644
new mode 100755
nguyenphusi commented 3 years ago

We faced the same issue after bumping up our prettier to version 2.3.2, prettier-stylelint --write threw the same error.

Although I don't even understand why but using stylelint-prettier seems to work for us πŸ˜‚ We installed the package:

npm install --save-dev stylelint-prettier

Then just added this to our .stylelintrc.js

{
  "plugins": ["stylelint-prettier"],
  "rules": {
    "prettier/prettier": true
  }
}

I'd love to know if anyone tried the same and success and can explain what happens under the hood πŸ˜„

MooseV2 commented 2 years ago

Will this be fixed or is it safe to consider this package to be abandoned?