Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Parse error: adjacent JSX elements must be wrapped in an enclosing tag

ErrorParse Error: Adjacent JSX elements must be wrapped in an enclosing tag

Short 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.

  • Applies to React 19, Vite 7, Next.js 15
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 build
  2. 2Match what you see, then jump to its fix

    1. 1The error points at the second top-level tag in a returnThe component returns two or more sibling elementsFix
    2. 2The 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. 3The component returns nothing, or the elements after the return are ignoredMarkup after return is on a new line without parenthesesFix

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.jsx

2Fix

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 dev

Confirmed by react.dev

Did this fix it?

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 -r

2Fix

Close each tag.

<img src="/logo.png" alt="Logo" />
<input type="text" />

3Verify

Reload. The parse error should be gone.

npm run dev

Confirmed by react.dev

Did this fix it?

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 -r

2Fix

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 dev

Confirmed by react.dev

Did this fix it?

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:

Related fixes

Web 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 fix

Web 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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.