Parse error: adjacent JSX elements must be wrapped in an enclosing tag
Parse Error: Adjacent JSX elements must be wrapped in an enclosing tagShort answer
A component can return only one JSX root, because JSX compiles to one JavaScript object. Wrap the siblings in one parent element or in a fragment (<> and </>). The same message also appears when a tag is not closed, so check every tag before wrapping.
Fix it fast
1Find out which cause you have
Go to the line and column the error names and look at the top level of the return. Count how many elements sit next to each other with nothing around them.
npm run build2Match what you see, then jump to its fix
- 1
The error points at the second top-level tag in a returnThe component returns two or more sibling elementsFix - 2
The error appears after a self-closing tag such as <img> or <input> or a <li> with no closing tagA tag is not closed, so the parser sees extra siblingsFix - 3
The component returns nothing, or the elements after the return are ignoredMarkup after return is on a new line without parenthesesFix
- 1
What does the error look like?
Parse Error: Adjacent JSX elements must be wrapped in an enclosing tag
Cause 1 of 3
The component returns two or more sibling elements
1Check
JSX is turned into plain JavaScript objects, and a function cannot return two objects without wrapping them. Two JSX tags need a wrapper in the same way.
grep -n "return (" -A4 src/App.jsx2Fix
Wrap them in one parent. If you do not want an extra div in the page, use a fragment: it leaves no trace in the browser HTML tree.
return (
<>
<h1>Todos</h1>
<ul>{items}</ul>
</>
)3Verify
Save and reload; the parse error is gone and the DOM has no extra wrapper.
npm run devConfirmed by react.dev
Cause 2 of 3
A tag is not closed, so the parser sees extra siblings
1Check
JSX needs every tag closed explicitly. <img> must be <img />, and <li>oranges must be <li>oranges</li>.
grep -nE "<(img|input|br|hr)[^/>]*>" src -r2Fix
Close each tag.
<img src="/logo.png" alt="Logo" />
<input type="text" />3Verify
Reload. The parse error should be gone.
npm run devConfirmed by react.dev
Cause 3 of 3
Markup after return is on a new line without parentheses
1Check
If the markup is not on the same line as the return keyword, it must be wrapped in parentheses; otherwise the code on later lines is ignored.
grep -n "return$" -A3 src -r2Fix
Open the parenthesis right after return and close it after the last tag.
return (
<div>
<Header />
<Main />
</div>
)3Verify
The component renders its content.
npm run devConfirmed by react.dev
How do I stop it coming back?
- Let the editor format JSX on save so a missing close tag stands out.
- Use a fragment when a wrapper div would break your CSS layout.
- Run ESLint in CI so a parse error is caught before merge.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- TaskvareA task and project-management suite: React on the web, Flutter on mobile, TypeScript underneath.
Related fixes
Web apps
ESLint says an element in a list is missing its key prop
react/jsx-key
react/jsx-key fires when an element returned from map, Array.from or an array literal has no key.
3 causes, each with a fixWeb apps
There is no tailwind.config.js after installing Tailwind 4 and HeroUI in Next.js
HeroUI components render unstyled
Nothing is broken: Tailwind CSS 4 is configured in CSS and no longer creates tailwind.config.js.
3 causes, each with a fixWeb apps
react-i18next shows the wrong plural form for a count, or prints the key instead of the text
t('item') prints the key item instead of a translated sentence
i18next picks a plural from the count option and looks for keys ending in _one, _other and so on.
4 causes, each with a fixWeb apps
useSession throws because there is no SessionProvider above it
[next-auth]: `useSession` must be wrapped in a <SessionProvider />
useSession reads the session from React Context, and SessionProvider is what creates that context.
3 causes, each with a fixWeb apps
next/link throws React.Children.only on its children
Error: React.Children.only expected to receive a single React element child.
React.Children.only accepts exactly one React element and throws for anything else, including an array with one item.
3 causes, each with a fixWeb apps
Hydration failed after adding next-themes dark mode
Console reports a server and client mismatch on the html element
next-themes changes the html element and knows the theme only in the browser, so server HTML and client HTML differ.
3 causes, each with a fix