IanVS / prettier-plugin-sort-imports

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

chore: upgrade babel parser version #153

Closed zxt-tzx closed 4 months ago

zxt-tzx commented 4 months ago

hello, bumping up the babel parser version because I am using prettier-plugin-sort-imports in my codebase and using latest using syntax resulted in a Prettier error

I poked around and found out it's because this syntax is is supported only since v7.22.0 of babel: see https://babeljs.io/blog/2023/05/26/7.22.0

thanks!

IanVS commented 4 months ago

Hi, thanks for the contribution. We don't use the using syntax and we don't pin our version of Babel like the trivago project does. So if you need to use a version of babel that is more recent than you have now, you should be able to just update your lockfile (either by deleting it and your node_modules and re-installing or by using a pnpm.overrides, or resolutions, or whatever your package manager requires.

I'll work on releasing a version soon that updates babel, but in the meantime at least you shouldn't be blocked.

zxt-tzx commented 4 months ago

Thank you for working on this and taking the time to reply! I'm not very familiar with how to override this and unblock myself.

This is the error message I get from Prettier:

["ERROR" - 20:05:42] Error formatting document.
SyntaxError: This experimental syntax requires enabling the parser plugin: "explicitResourceManagement". (28:2)
    at constructor (/Users/xxx/project/node_modules/@ianvs/prettier-plugin-sort-imports/node_modules/@babel/parser/lib/index.js:356:19)

What I've done:

  1. added "overrides": { "@babel/parser": "^7.24.0"} to pnpm under package.json
  2. installed and added '@babel/plugin-proposal-explicit-resource-management' to the plugins in prettier.config.cjs
  3. deleted and reinstalled my node_modules

however, I'm still getting the error from Prettier.

Would appreciate any tips, thank you so much for working on this and taking the time to reply!

IanVS commented 4 months ago

Ah, thanks for sharing the error. It sounds like you need to add explicitResourceManagement to importOrderParserPlugins in the prettier config. If that doesn't work, would you mind opening an issue and sharing your prettier config so I can help troubleshoot there?

zxt-tzx commented 4 months ago

Ah, thanks for sharing the error. It sounds like you need to add explicitResourceManagement to importOrderParserPlugins in the prettier config. If that doesn't work, would you mind opening an issue and sharing your prettier config so I can help troubleshoot there?

will do, thank you so much!

zxt-tzx commented 4 months ago

oh wait, after updating all the related dependencies and adding explicitResourceManagement to importOrderParserPlugins in the prettier config, the error has gone away.

no need for anything else (overriding or installing @babel/plugin-proposal-explicit-resource-management).

thank you so much! will close this now.