IanVS / prettier-plugin-sort-imports

An opinionated but flexible prettier plugin to sort import statements
Apache License 2.0
984 stars 25 forks source link

Error: unknown type: "ChainExpression" #148

Closed rawand-faraidun closed 7 months ago

rawand-faraidun commented 7 months ago

This error is ta prettier error in general: Error: unknown type: "ChainExpression", but i get it when using prettier with this package and has no problem when removing it, the error seems to be happening because of optional chaining operator ? like config?.defaultLocale

Environment

Describe the bug

i believe it is related to this problem in prettier https://github.com/prettier/prettier/pull/13735, but it is fixed in prettier but somehow still happens with this package, to see the files I have a public repository that has this problem https://github.com/rawand-faraidun/linguify, it happens when using command line prettier. can be tested on files like validate.ts, AddKey.tsx

Configuration File (cat .prettierrc, prettier.config.js, .prettier.js)

// .prettierrc.json

{
  "trailingComma": "none",
  "tabWidth": 2,
  "useTabs": false,
  "semi": false,
  "singleQuote": true,
  "arrowParens": "avoid",
  "printWidth": 125,
  "endOfLine": "crlf",
  "overrides": [
    {
      "files": "*.tsx",
      "options": {
        "tabWidth": 2,
        "useTabs": false,
        "jsxSingleQuote": false
      }
    },
    {
      "files": "*.css",
      "options": {
        "singleQuote": false
      }
    }
  ],
  "importOrder": [
    "<BUILTIN_MODULES>",
    "fs",
    "express",
    "^(react/(.*)$)|^(react$)",
    "^(react-router-dom/(.*)$)|^(react-router-dom$)",
    "<THIRD_PARTY_MODULES>",
    "^@/(.*)$",
    "^[.]",
    "^@lib",
    ".css$"
  ],
  "plugins": ["@ianvs/prettier-plugin-sort-imports"]
}

Contribute to @ianvs/prettier-plugin-sort-imports

fbartho commented 7 months ago

This package depends on your node_modules-installed version of prettier.

This means that even if globally you have a higher version, you might have a lower version in your node_modules dir! Can you verify your lockfile or node_modules to figure out what version of prettier you have installed locally for that project?

A clean install or a force upgrade of prettier may resolve the issue!

If it still occurs, it'd be helpful to get the full call stack when the error appears.

rawand-faraidun commented 7 months ago

@fbartho you were right, the problem was because of globally installed prettier

thanks