VS Code problem: When I save, rows and spaces add automatically and destroys code

Viewed 2194

I'm using VS code and when I save, it automatically adds extra spaces and rows in tags and other parts of the code. After I change it back to the previous syntax and save again, this problem repeats and then my code couldn't work.

Recently I changed some property in my settings, I think it is connected to a "Prettier" extension, and since then I have this problem, but I don't remember which one to enable now in order to fix it.

For example here is an original code syntax in JS file:

import React, { useState } from 'react';

function App() {
  return ( null);
  <div>

  </div>
}

export default App;

And this is what happens after I save:

import React, {
  useState
} from 'react';

function App() {
  return (null); <
  div >

    <
    /div>
}

export default App;

I can't bring it back to correct syntax (delete unnecessary rows and spaces) when I change it back and save again - it does the same thing. I made changes like the offer here (add rewrap) and there (trim settings), but it didn't help.

I tried to uninstall and then reinstall my program, but it didn't help. My VS code version doesn't have the Tools option that may help.

1 Answers

I also faced a similar issue as shown here:

issue

Select "JavaScript React" instead of "JavaScript" as shown here:

fixed

Related