prettier-stylelint icon indicating copy to clipboard operation
prettier-stylelint copied to clipboard

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

Open etylsarin opened this issue 4 years ago • 13 comments

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 Version: 2.0.4
  • Running Prettier via: prettier-stylelint
  • Runtime: Node.js v10.18
  • Operating System: macOS Catalina Steps to reproduce:

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 avatar Apr 09 '20 13:04 etylsarin

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.

etylsarin avatar Jun 02 '20 15:06 etylsarin

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

binarykitchen avatar Aug 18 '20 23:08 binarykitchen

+1

kyrstenkelly avatar Oct 02 '20 14:10 kyrstenkelly

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

agursoyy avatar Oct 23 '20 18:10 agursoyy

Hey, anybody?

lucypoly avatar Nov 11 '20 15:11 lucypoly

+1

siiick avatar Dec 17 '20 16:12 siiick

+1

a-vershinin avatar Jan 03 '21 21:01 a-vershinin

+1

iMakedonsky avatar Mar 01 '21 13:03 iMakedonsky

+1

vnaik-isc avatar Mar 14 '21 11:03 vnaik-isc

Anyone working on it??

Sebastp avatar May 02 '21 17:05 Sebastp

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

AnirudhMergu avatar May 22 '21 00:05 AnirudhMergu

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 😄

nguyenphusi avatar Sep 09 '21 09:09 nguyenphusi

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

MooseV2 avatar Oct 13 '22 18:10 MooseV2