Fragment shorthand syntax error
Quick summary
You used the fragment shorthand <> incorrectly — it cannot accept attributes and must be properly closed with </>.
Why this happens
The fragment shorthand is missing its closing </> tag
You tried to pass a key or other attributes to the shorthand <> which does not support attributes
You nested fragment shorthands incorrectly, causing the transpiler to misparse the JSX
Minimal example
function App() {
return (
<>
<Header />
<Content />
// missing </>
);
}function App() {
return (
<>
<Header />
<Content />
</>
);
}
// With key: <React.Fragment key={item.id}>...</React.Fragment>Adding the closing </> tag completes the fragment, making the JSX valid and parseable.
How to diagnose
Check the compiler error for the fragment syntax issue and the line number
Verify every <> has a matching </> closing tag
If you need to pass a key, use <React.Fragment key={...}> instead of the shorthand
How to fix
Add the missing </> closing tag for the fragment shorthand
Switch to <React.Fragment key={key}>...</React.Fragment> when you need to pass attributes like key
Simplify the JSX structure to avoid deeply nested fragment shorthands that are hard to parse
How to prevent
Use the explicit React.Fragment syntax when you need keys or attributes, and <> only for attribute-free fragments
Use an editor with JSX support that highlights mismatched fragment tags