next.js: NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.
Link to the code that reproduces this issue
https://github.com/Abdulahadahmadi/codewithahad.git
To Reproduce
I have a web app in Nextjs in Navbar component when I go to other router and return to main route it show the above error that I attach in title.
Current vs. Expected behavior
I tried many ways in stackoverflow and github issue that people suggested but I couldn’t find the solution for this problem.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
operating system: window 11
next.js v 14
node v 20
Which area(s) are affected? (Select all that apply)
Routing (next/router, next/navigation, next/link)
Additional context
I host this app in vercel
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 23
- Comments: 33 (2 by maintainers)
Commits related to this issue
- PROD BUG FIXED : Layout fragment bug fixed as discussed here https://github.com/vercel/next.js/issues/58055#issuecomment-2198556687 ; meta description updated — committed to Astrobot-me/bubbler by Astrobot-me 2 years ago
- PROD BUG FIXED 2: Layout fragment bug fixed as discussed here https://github.com/vercel/next.js/issues/58055#issuecomment-2198556687 — committed to Astrobot-me/bubbler by Astrobot-me 2 years ago
if you get this error when you want to create multiple layout.jsx files for different parts of your application make sure to return a react fragment (<></>) from any layout.jsx component Except the root layout. so DO NOT return html and body tag again.
Same issue here with internationalization. We are using
next 13.5.6withnext-intl.Edit For anyone struggling with this when using internationalization, I was able to fix it with this solution from another tread. Just add a
not-found.tsxfile in the root of[locale]dir.And if you want to use the same next 404 interface you can add the following:
[locale]/not-found.tsxGuys, I found solution.
If yout want to use option
localePrefix = 'as-needed'in file middleware.ts and in page, for example, /es/about/ everything is ok, but in page /about/ aplication is crushing, you should check option matcher in your middleware.ts file. I had this error when my config looked like that:I changed to
and now everything is ok.
p.s.: If you’re interested, I found this when I added the files to app directory (not in [locale]):
not-found.tsx:
layout.tsx :
After that, I saw that I had a 404 error page on the “/about” page. This is a lot better than when the application crashed.
https://next-intl-docs.vercel.app/docs/routing/middleware#locale-prefix-as-needed Here in documentation written: 1. If you use this strategy, you should make sure that your matcher detects unprefixed pathnames.
I’m seeing the same error in production (
next-intl@3.3.2andnext@14.0.4) but it happens spontaneously upon navigation and can’t be reproduced consistently. I already have a[locale]/not-found.tsxfile, so that doesn’t help unfortunately.Error displayed in the browser:
Error logged in the console:
Yes, after adding multilingual support to Next.js, I also encountered this issue and couldn’t figure out the cause.
still exists in next 15 btw
Thanks a lot, it’s work for me
Im having the same issue when trying to redirect to
notFound(), like this:FYI my issue was I was missing a layout.tsx at the root /app/ folder. I am using internationalization, so I have app/[locale]/ directory structure. My root layout was sitting at /app/[locale]/layout.tsx, but since moving it to /app/layout.tsx my
notFound()invocations do render the 404 Not Found page successfully.The same is happening with me. I think the error thrown is somehow captured
NextIntlClientProviderinstead of falling back to NextJS ErrorBoundary. I tried importing theErrorBoundaryand wrapping the content inside theNextIntlClientProviderwhich prevented the crash on the client, but it didn’t show the 404 page. Instead it was telling me that nextjs encountered an error and I should check the browser console for more details.I was getting this same error, but I realised that I am using next-intl for my entire web app, and I have placed not-found.tsx in app/not-found.tsx, but instead, it should be inside app/[locale]/not-found.tsx and the issue is resolved by doing that.
Man… this helped me a lot and this is the legit solution I guess…
I had same problem when I have started using next-i18n navigation, and I mixed from where I do “import { Link }” so I stared having such issue when Link was imported fromo “next”, then I realized I should import from my “navigation.ts”, so like:
import { Link } from @/src/navigation@codewithahad01 Thank you for sharing!
Is it possible to clarify how exactly we can replicate this? I was not able to replicate it with the latest stable v14.0.4.