Accepted answer

in the end what did the trick was changing the file format from javascript to javascript react on the bottom toolbar. i'm publishing it here for future reference since i didn't find any documentation on this topic.

enter image description here

in addition to the above. if you click 'configure file association for .js' you can set all .js files to javascript react


add this in your .js code,

/* prettier-ignore */


prettier is an opinionated code formatter. it enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. include : javascript typescript flow jsx json css scss less html vue angular graphql markdown yaml


extensions i use

not allowed to post a picture yet, but this is the extensions i use.
the first one is called beautify - helps with html, css, js
the second one is rc-beautify - helps with ts, js, react.

also babel javascript is used as the language mode.


here is what worked for me-

i clicked on the language mode (javascript react) at the bottom of the screen

enter image description here

then chose the configure react javascript language based setting option

enter image description here

then changed the javascript react default formatter to prettier as shown in the pic.

enter image description here

that pretty much did it for me after i saved the react file.


you can install an extension like react-beautify that helps you format your jsx code.

it is found here

this extension wraps prettydiff/esformatter to format your javascript, jsx, typescript, tsx file.


i had similar problem, then i found out it was caused by 'beautify' extension. after i uninstalled the extension, everything is working fine.


i had to disable the js-css-html formatter extension in vsc. only solution to this problem


after reading many great suggestions and workarounds, i discovered that i could simply place my mouse arrow down over the bright blue horizontal bar at the bottom of vscode editor window - right click - which opens a popup list window - and deselected = "editor indentation".


you can double click javascript in the status bar at the bottom of vscode, and then change the format from javascript to react (choose react in the select language mode to associate with '.jsx')


i just added all the combinations mentioned above.

  1. added this
"files.associations": {
    "*.js": "javascriptreact"
  1. added this also
"beautify.ignore": ["**/*.js","**/*.jsx"]
  1. deleted additional js formatting
  2. installed prettier
  3. turn on prettier and formatting


make sure you dont have multiple javascript formatters enabled in your current workspace. (you have to disable the rest of them for your current workspace).

react-beautify mostly does the magic but fails if you have some other js formatter/beautifier already installed.

in my case, i had react-beautify and js-css-html formatter extension installed. i had to disable the js-css-html formatter for my current workspace.


install prettier (if not installed by default) and try to add this to your user or workplace settings:

"prettier.jsxbracketsameline": true

do not put linebreak between return and the returned jsx expression.

trigger autoformat (alt+shift+f) and check if works.


i struggled with this but finally found a solution. this is my settings.json

    "": "c:\\program files\\git\\bin\\bash.exe",
    "workbench.startupeditor": "welcomepage",
    "window.zoomlevel": 1,
    "emmet.includelanguages": {
        "javascript": "javascriptreact",
        "vue-html": "html"
    "editor.formatonsave": true,
    "javascript.updateimportsonfilemove.enabled": "always",
    "editor.wordwrap": "on",
    "editor.tabsize": 2,
    "editor.minimap.enabled": false,
    "workbench.icontheme": "vscode-icons",
    "eslint.autofixonsave": true,
    "eslint.alwaysshowstatus": true,
    "beautify.ignore": [
    "prettier.jsxsinglequote": true,
    "prettier.singlequote": true

i added

"beautify.ignore": ["**/*.js","**/*.jsx"]


open the visual studio code settings. refer the image below to see how to navigate to the settings.

open vscode settings

once the settings tab is open. if you want to make the settings changes for all the projects then select the user sub tab, if only for current project then select the workspace sub tab.

add file associations

type "file associations" in the search text box and press enter.

click on add item.

  • set item : *.js
  • set value : javascriptreact

above changes will start associating all *js files in the project as javascript react files.

next open any .js file in your project and right click and select format document. if you have multiple formatters then associate your favorite formatter. i have used prettier to handle my formatting.


alternatively, saving the file with a .jsx extension resolves this in vscode.

i had the same challenge and i am hoping to discover a better way of handling this issue in vscode.

i noticed your suggested work-around has to be done each time you open the react file with an extension of .js


you can prevent vsc from incorrectly formatting your jsx by adding an association in your settings.json

code > preferences > settings

in the settings window search for associations, click edit in settings.json and then add:

"files.associations": {
    "*.js": "javascriptreact"


change vscode preferences settings > user settings below:

"files.associations": {

Related Query

More Query from same tag