Visual Studio code error while saving react files?

Viewed 10124

enter image description here

And when i am saving this file with Ctrl+s even using prettier and other javascript extension snippets in visual code i am getting this deformed code which is showing errors enter image description here

And Showing error as:

JSX element div has no corresponding closing tag.
JSX element Navbar has no corresponding closing tag.
JSX element NavbarBrand has no corresponding closing tag.
Identifier expected.
> expected.

9 Answers

The problem is you've installed Beautify as well as Prettify both in your Vscode. Beautify is causing this problem. I tried removing beautify and it worked like a charm. Just remove beautify and use prettify and it will work absolutely well.

Change your file extension to .jsx so the formatter knows that it contains markup

  1. Click 'javascript' in the bottom - right

  2. Then it will come a search bar.

  3. In there you need to search react

  4. Then select the first search result.

  5. DONE

You may have installed a formatter that not suit for html+js code snippets. uninstall (not work whether disable) it and set the default formatter in vs code.

The way I learned to do it is: The problem is probably that you are using a .js file but intend for it to run React. Now naturally, Vs code would identify this by itself if you saved it as a .jsx, but you don't want that. Simply click on the bottom right on VS Code Editor where it says Javascript.

You will see an option to Select the language Mode, here you can search for JavaScriptReact and select. That's it. This should solve your problem.

type the following commands before creating a new app:

npm install -g create-react-app
npx create-react-app myapp
cd myapp
npm start
Related