Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaks with import assertions (assert { type: 'json' }) #251

Closed
jthrilly opened this issue Mar 4, 2024 · 4 comments
Closed

Breaks with import assertions (assert { type: 'json' }) #251

jthrilly opened this issue Mar 4, 2024 · 4 comments
Assignees
Labels
question Further information is requested

Comments

@jthrilly
Copy link

jthrilly commented Mar 4, 2024

What version of prettier-plugin-tailwindcss are you using?

0.5.11

What version of Tailwind CSS are you using?

3.4.1

What version of Node.js are you using?

LTS

What package manager are you using?

pnpm

What operating system are you using?

macOS

Describe your issue

As per this issue: trivago/prettier-plugin-sort-imports#270

The sort imports plugin included by this plugin doesn't work properly with import assertions. My project does not use the import sorting plugin, so this should not impact me - but it does. Prettier crashes when trying to format any file with an import assertion with the error caused by the above plugin:

["ERROR" - 11:37:33] Error formatting document.
SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "importAttributes", "importAssertions". (3:48)
@thecrypticace
Copy link
Contributor

Note that we don't include any plugins — if you don't have the sorting plugin installed then support for it won't be loaded — but this is probably is related to the use of the babel parser elsewhere. I'll take a look. Thanks!

@thecrypticace thecrypticace self-assigned this Mar 4, 2024
@jthrilly
Copy link
Author

jthrilly commented Mar 4, 2024

Note that we don't include any plugins — if you don't have the sorting plugin installed then support for it won't be loaded — but this is probably is related to the use of the babel parser elsewhere. I'll take a look. Thanks!

I completely understand and agree, which is why I was so surprised to be impacted by this. I am not using either @trivago/prettier-plugin-sort-imports or @ianvs/prettier-plugin-sort-imports in my project - they are installed as peer deps of prettier-plugin-tailwindcss.

My prettier config, for reference:

import { fileURLToPath } from "url";

/** @typedef {import("prettier").Config} PrettierConfig */
/** @typedef {import("prettier-plugin-tailwindcss").PluginOptions} TailwindConfig */

/** @type { PrettierConfig | TailwindConfig } */
const config = {
  plugins: [
    "prettier-plugin-tailwindcss",
  ],
  tailwindConfig: fileURLToPath(
    new URL("../../tooling/tailwind/fresco.ts", import.meta.url),
  ),
  tailwindFunctions: ["cn", "cva"],
  printWidth: 80,
  quoteProps: 'consistent',
  singleQuote: true,
};

export default config;

@thecrypticace
Copy link
Contributor

@jthrilly Hey, any chance you could provide a reproduction? Like a file that always crashes or something? I'm testing this right now and it definitely works for me.

Also, can you provide your exact Node version? I'm using Node 18 but if you're using something different it might be related.

@thecrypticace thecrypticace added the question Further information is requested label Mar 7, 2024
@jthrilly
Copy link
Author

jthrilly commented Mar 8, 2024

You're absolutely correct that this doesn't repro - I tried now with a fresh repository and things are working correctly.

I can only assume that because I was working in a monorepo the configuration changes I made to the tailwind package were not being propagated correctly until after I restarted/ran pnpm install again.

Really sorry for the noise! Thanks for all your work.

@jthrilly jthrilly closed this as completed Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants