Visual Studio code error while saving react files?
Asked Answered
H

8

11

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.

Heterologous answered 2/11, 2018 at 9:29 Comment(5)
Your file is a .js file when it should be a jsxOutofdate
But i am making react app which has extension .jsHeterologous
It doesn't change anything for react, only for vscode formatterOutofdate
It worked !! Thank You so much :)Heterologous
Possible duplicate of Prettier/VSCode Eslint weird format/syntax breaking bugDelve
O
2

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

Outofdate answered 2/11, 2018 at 10:10 Comment(0)
C
7

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.

Clean answered 18/3, 2020 at 3:1 Comment(0)
O
2

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

Outofdate answered 2/11, 2018 at 10:10 Comment(0)
C
0

Another variant: change your settings to:

P.S: Change language to JSX in Visual Studio Code

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

That way you can either keep your extension as .js

Chucho answered 26/4, 2020 at 19:59 Comment(0)
P
0

change language mode to javascript react [the language mode should be javascript react as circled] https://i.sstatic.net/DDQUH.jpg

Poliomyelitis answered 21/10, 2021 at 8:46 Comment(0)
U
-1

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.

Unbowed answered 29/10, 2019 at 11:18 Comment(0)
A
-1

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.

Aha answered 10/3, 2021 at 16:45 Comment(0)
S
-2

1 Disable all extension 2 And select the language mode is JavaScriptReact [see pic is here ] [1]: https://i.sstatic.net/uOwiT.png

Shilling answered 29/11, 2020 at 11:10 Comment(0)
C
-3

type the following commands before creating a new app:

npm install -g create-react-app
npx create-react-app myapp
cd myapp
npm start
Cudlip answered 29/10, 2020 at 17:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.