'Single quote in tsx file with prettier

For 2-3 weeks, while I didn't change anything in prettier file, VSC started changing single quotes to double quotes, while it was always single quotes. I tried many options but it keeps changing it. Heres my .prettierrc

{
  "trailingComma": "es5",
  "printWidth": 200,
  "semi": true,
  "singleQuote": true,
  "jsxSingleQuote": true,
  "tabWidth": 2,
  "quoteProps": "as-needed"
}

EDIT: I think, that it is a matter of .tsx files, as prettier has just option for .jsx files but still didn't find a solution.



Solution 1:[1]

In .prettierrc, add:

{
  "singleQuote": true,
  "jsxSingleQuote": true
}

Solution 2:[2]

create a .prettierrc file on your root folder and add:

{
  "singleQuote": true
}

Solution 3:[3]

On your User Settings make sure you have the following line:

"prettier.singleQuote": true

You can access the user settings by CTRL+, on windows or CMD+, on mac.

If you're using the settings GUI just search for single quote and check/uncheck the Prettier: Jsx Single quote and Prettier: Single quote

Solution 4:[4]

I have the same issue for a few days. I checked all the settings and they seem to be fine.

At the moment THE ONLY thing that helps is downgrading down to the previous version of Prettier in my case it was version 2.3.0 (I didn't check all the versions between this and the latest but few of them had the same issue)

Solution 5:[5]

Best place to read up on this configuration is the website. https://prettier.io/docs/en/configuration.html

If you are using a package.json, create a new key if you dont have a "prettier" key.

"prettier":{
    "singleQuote": true
}

Or you could create a .prettierrc file written in JSON and add the same key pair value.

Solution 6:[6]

add tsxSingleQuote: true, in prettierrc.js file

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edmar Miyake
Solution 2 Joseph Briggs
Solution 3 I am L
Solution 4
Solution 5 DSam87
Solution 6 Sushan Yadav