ggascoigne / prettier-plugin-import-sort

Prettier plugin to pass javascript and typescript through import-sort
MIT License
110 stars 11 forks source link

Error: Cannot find module 'prettier/parser-babel' #12

Closed rerodrigues closed 3 years ago

rerodrigues commented 4 years ago

I don't know exactly why this happens, but when running prettier via eslint --fix I got this error.

the error is trown by prettier-plugin-import-sort/src/index.js line

const { parsers: javascriptParsers } = _interopDefault(
  require('prettier/parser-babel')
)

even I'm using TS

below is my conf on package.json

  "importSort": {
    ".ts, .tsx": {
      "style": "renke",
      "parser": "typescript"
    }
  },

and my lint-staged config which is firing the eslint --fix

  "lint-staged": {
    "*.{js,ts,tsx,jsx}": [
      "eslint --fix"
    ]
  },

EDIT: Even if I run $(npm bin)/prettier manually, the same error happens

ggascoigne commented 4 years ago

Not at my computer right now, but I’m guessing that you aren’t using the latest versions of prettier and prettier-plugin-import-sort.

On Wed, Jun 10, 2020 at 5:52 PM Renato Rodrigues notifications@github.com wrote:

I don't know exactly why this happens, but when running prettier via eslint --fix I got this error.

the error is trown by prettier-plugin-import-sort/src/index.js line

const { parsers: javascriptParsers } = _interopDefault( require('prettier/parser-babel') )

even I'm using TS

below is my conf on package.json

"importSort": { ".ts, .tsx": { "style": "renke", "parser": "typescript" } },

and my lint-staged config which is firing the eslint --fix

"lint-staged": { "*.{js,ts,tsx,jsx}": [ "eslint --fix" ] },

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ggascoigne/prettier-plugin-import-sort/issues/12, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACAVVCEV3VKQTOS7TYNMXDRWATC7ANCNFSM4N26GHFA .

kevinfarrugia commented 4 years ago

I have received the same error and it was resolved by updating to prettier: ^2.x.x (previously was on prettier 1.x.x).

c10b10 commented 3 years ago

This error was fixed by using the latest version of Pettier, but I'm now getting TypeError: style is not a function.

malthejorgensen commented 3 years ago

@c10b10 Had the same issue just now. The mistake was that I hadn't used the right format for the importSort config in package.json. It doesn't tell you if it's malformed and then falls back to node_modules/eslint/lib/api.js as the style, which doesn't work.

Not working

// package.json
"importSort": {
  "*.js": {
    "style": "module",
  }
},

Working

// package.json
"importSort": {
  ".js": {
    "style": "module",
  }
},
ggascoigne commented 3 years ago

Thanks for pointing this out, I'll make note of this in the readme.

ggascoigne commented 3 years ago

FYI the next release is going to drop prettier v1 support, v2 has been out long enough now that this shouldn't be too much of a problem.