withastro / prettier-plugin-astro

Prettier plugin for Astro
Other
475 stars 33 forks source link

🐛 BUG: Formatter is crashing due to prettier updates #386

Closed ahmad-ali14 closed 8 months ago

ahmad-ali14 commented 10 months ago

Describe the Bug

I'm getting this error:

["ERROR" - 15:24:12] printer.embed has too many parameters. The API changed in Prettier v3. Please update your plugin. See https://prettier.io/docs/en/plugins.html#optional-embed
Error: printer.embed has too many parameters. The API changed in Prettier v3. Please update your plugin. See https://prettier.io/docs/en/plugins.html#optional-embed
    at printEmbeddedLanguages (file:///Users/.../node_modules/.pnpm/prettier@3.0.3/node_modules/prettier/index.mjs:17669:11)
    at printAstToDoc (file:///Users/.../node_modules/.pnpm/prettier@3.0.3/node_modules/prettier/index.mjs:17800:9)
    at async coreFormat (file:///Users/.../node_modules/.pnpm/prettier@3.0.3/node_modules/prettier/index.mjs:18111:14)
    at async formatWithCursor (file:///Users/.../node_modules/.pnpm/prettier@3.0.3/node_modules/prettier/index.mjs:18309:14)
    at async Module.format2 (file:///Users/.../node_modules/.pnpm/prettier@3.0.3/node_modules/prettier/index.mjs:21504:25)
["INFO" - 15:24:12] Formatting completed in 18ms.

I have two formatters installed (for astro files):

Screenshot 2023-11-14 at 15 35 02

and the config file:

// prettier.config.cjs
const config = {
  tabWidth: 2,
  semi: true,
  singleQuote: true,
  plugins: ['prettier-plugin-astro'],
  overrides: [
    {
      files: '*.astro',
      options: {
        parser: 'astro',
      },
    },
  ],
};

module.exports = config;

Steps to Reproduce

  1. upgrade all astro components to the latest as shown below.
  2. Try to format any Astro file using Prettier
  3. Prettier will fail and you can look in the outputs for log.

Relevant packages Versions:

{
  "dependencies":{
    "astro": "3.5.3",
  },
  "devDependencies": {
    "@astrojs/check": "^0.3.1",
    "@astrojs/mdx": "1.1.4",
    "@astrojs/node": "6.0.3",
    "@astrojs/react": "^3.0.4",
    "@astrojs/rss": "3.0.0",
    "@astrojs/sitemap": "3.0.3",
    "@astrojs/tailwind": "5.0.2",
    "@astrolib/seo": "0.6.0",
    "astro-eslint-parser": "0.14.0",
    "@types/node": "^20.8.4",
    "@vitest/ui": "~0.32.4",
    "prettier": "^3.0.0",
    "semantic-release": "^21.1.2",
    "semantic-release-slack-bot": "^4.0.2",
    "tsx": "^3.13.0",
    "typescript": "^5.2.2",
    "vite": "~4.3.9",
    "vite-plugin-dts": "~2.3.0",
    "vite-tsconfig-paths": "~4.2.1",
    "vitest": "0.34.1"
    }
}
ahmad-ali14 commented 10 months ago

I downgraded to prettier@2.8.8 and seems to be solving the issue for now.

Princesseuh commented 8 months ago

This is most likely happening because of a transitive dependency causing the wrong version of the Prettier plugin or Prettier itself being used, which shouldn't really happen anymore. The latest version of the plugin is only compatible with Prettier 3 and works correctly with the latest version of Prettier.

Please re-open an issue if you can reproduce this using the latest version of everything!