kitql icon indicating copy to clipboard operation
kitql copied to clipboard

Prettier crashes when importing json and asserting json type

Open harshmandan opened this issue 1 year ago • 3 comments

Describe the bug

When I try to import a json file inside a .js/.ts file and try to save it prettier crashes.

Severity

blocking an upgrade

Steps to Reproduce the Bug

Here's a sample file:

import firebaseJSON from '../../../firebase.json' assert { type: 'json' }

...

setKeys(firebaseJSON.emulators)

Saving this results in a crash with following log:

["ERROR" - 13:11:35] Error formatting document.
SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): "importAttributes", "importAssertions". (1:35)
...

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-6f9a3r?file=package.json,src%2Flib%2Futils%2Ftest.ts

To see the error you'll need to download the project and run it locally. All you have to do is try to save and format the lib/utils/test.ts file with prettier.

harshmandan avatar Feb 16 '24 07:02 harshmandan

Thx for reporting, I'll have a look.

jycouet avatar Feb 16 '24 08:02 jycouet

I can reproduce 👍 But didn't manage to find an easy fix :/

jycouet avatar Feb 18 '24 21:02 jycouet

It's linked to https://github.com/trivago/prettier-plugin-sort-imports/issues/270

Even if I'm using a fork https://github.com/IanVS/prettier-plugin-sort-imports coming from https://github.com/the-guild-org/shared-config/blob/main/packages/prettier-config/package.json#L24

Deps hell :/

jycouet avatar Mar 14 '24 16:03 jycouet