nuxt: Error while initializing app DOMException: Failed to execute 'appendChild' on 'Node': This node type does not support this method. at Object.We [as appendChild]
I have an error
Error while initializing app DOMException: Failed to execute 'appendChild' on 'Node': This node type does not support this method.
at Object.We [as appendChild]
nuxt “version”: “1.0.0”,
I do npm run build and npm run start.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 34
- Comments: 86 (12 by maintainers)
Commits related to this issue
- :bug: :ambulance: try fix error https://github.com/nuxt/nuxt.js/issues/1552 — committed to PierreTsia/fontenille-house by PierreTsia 5 years ago
Faced the same problem, found a not very good solution, but as a temporary crutch can be someone help. If you set the boot flag and change it in the creation hook, the error can be avoided.
@Timkor It may related to auth cookie.
I just found that the error occur when I use nuxt-auth with bootstrap-vue’s navbar.
appendChild error:
it works:
If anybody else has this issue, You’d better check if there is at least one child in some specific component(You can search ‘v-if’ keyword in your project). I think it not related to nuxt issue.
@BlazerYang This is what caused my error:
<nuxt-link :class="style.subNavLink" class="relative" to="/">CONFIGURATOR <app-nav-selected v-if="$nuxt.$route.name === 'index'" class="app-nav-selected absolute"></app-nav-selected> </nuxt-link>Was the v-if changed it to a v-show.
Put a breakpoint in your javascript and you will find the exact node that is causing it.
Not Quite sure why it was a problem yet though
Hi,
This bug was due to
generate.minify.collapseWhitespacewhich was true by default, it will befalseby default in1.0(next release).in the meantime, to fix this issue, you can add in your
nuxt.config.js:I have the same error, with generated static after a
yarn generatein the console dev, but the page appears to be displayed correctly.Edit : I have this error only with
yarn generate.yarn dev&yarn startwork well.Any movement on this? I’m seeing this even in a recent
nuxt-edge(2.0.0-25594102.4311aca)Hi I’m still watching this error Changing options
generate.minifynot solve the problemAnother update, this issue is caused by Cloudflare for me. I’ve tried a lot of things and one of the last differences with my local server was Cloudflare. I’ve disabled Auto Minify and everything worked
no-ssr component in Vue solved this for me… just wrapped the offending code and problem gone.
I’ve created a minimal reproduce repo here: https://github.com/meteorlxy/vuepress-appendchild-error
I met this problem in VuePress, but I think it’s the same cause.
Here are some of the workarounds and the possible explainations:
v-iftov-show.v-showwill render the element withdisplay: none, rather than<!---->.createdhook.createdhook will be executed by server-renderer, so that itv-ifblock will be server-rendered, rather than<!---->.v-elseelement. This will render an empty element rather than<!---->.Edit: Please forgive me, I have just discovered that, in my case, the error was created by invoking the v-html directive using badly formed html. A closing
</blockquote>tag was inserted without a corresponding opening tag Thanks so much for nuxt.js!I have the same error. The interesting thing is that the error is only created upon reloading the page, or else invoking the url. AND only upon doing
npm run buildandnpm start, it never occurs undernpm run dev. So to reproduce the error, I need to build and do npm start, then reload the offending page (or else invoke its url directly in the browser).It is a long text containing html and I am using the v-html directive.
@CsabaSzabo I found that
v-if="false"resulted in an empty comment<!---->there, which could be the reason of this error. An emtpy<div v-else>will repalce<!---->with<div></div>, and everything works well.Maybe related to https://github.com/vuejs/vue/issues/5117
@unwrittenmike same issue here. changed v-if with v-show and the issue was solved…
I’m having a hard time fixing this issue.
For me it appears once deployed (with
nuxt buildnpm run build) when there is already a cached version in the browser. Once all data cleared it works like a charm 🤔Any suggestions? Could it be because of a caching issues?
I struggled with this issue and found my root cause:
@NishantSinghChandel Take a look at all your v-if’s… Make sure that your are not trying to do any DOM updates to DOM nodes that are not present due to the condition of a v-if… Use v-show to get around this if possible
OUCH. Same error occurring only in generated project, no sign of any error in dev.
Tried SmelayaPanda’s solution, but didn’t help.
I ultimately had to work my way through dismantling all manner of things in the project until I found for whatever reason that my use of FontAwesomeIcon in multiple components was the culprit. Stripped out all of the font-awesome-icon instances, but the problem persisted until I yanked the plugin loading FontAwesomeIcon globally. Much better now, even if my app now needs a lot of visual surgery.
This was a monster project I’ve been working on for a couple of months in dev, should have tried to deploy much earlier in the lifecycle. Hope others learn vicariously from my poor judgement there.
Regardless, this error seems to have several manifestations, and it’s virtually impossible to diagnose sensibly in production builds. Since it only occurs in production builds, that’s pretty frustrating. Not clear still if this is a Vue or Nuxt centric issue, but it doesn’t feel like this issue should have been closed.
In my case, the issue is caused by v-if on a v-for loop. The v-if generates a comment when not to be rendered. And usually a Vue-Warning saying mismatching virtual nodes and DOMs should logged out maybe becasuse the comment is recognized as a DOM. But somehow this time it just causes an error. Changing v-if to v-show solved my issue.
I’m also experiencing this error on this page:
It only occurs when I have successfully logged in and then I refresh the page (refresh on no authUser results in cleanly rendering the v-if section).
Also, I get a slightly different error when I “npm run dev”. Instead of the posted error, I get a [vue warn] about the virtual DOM, and a subsequent error about not being able to call .toLowerCase on something during app initialization.
Nice @NWRichmond , You saved my mid-night work. I have add
<clent-only>wrapping the<form>and It’s work fine for me.I was running into the same problem when deploying on a statically-generated Nuxt app on Netlify, even though I wasn’t using Netlify Forms. I suspect it’s because of the way Netlify transforms html during the deploy step. There were no issues when the site was statically built and served somewhere other than Netlify.
I worked around this issue by wrapping the offending
<form>-containing component with<client only></client-only>.I’m running into the same problem due to Netlify Forms. However, adding the hidden field directly in my code hasn’t solve my problem.
A small guide on how to deal with this error (result of failing hydration)
I’m also getting this error with nuxt generate. I can reproduce it locally when building and serving the
distfolder. Unfortunately I can’t reproduce this on the dev server so it’s reeaaaaally hard to debug.Does anyone have a clue how to narrow down the nodes that are causing this?
@gangsthub yes I am using version 1.0.0. And 2.0 release notes states there is no breaking changes so I’d upgrade nuxt and lookout for this issue. Thank you.
Hi, I am also getting this error on production sometimes. And its gone after a refresh. It never happened on my local development environment. The site normally looks okay in this condition but nothing works until I do a page refresh. This is the stacktrace it generates
This error is so random and gone after a refresh, I can not even debug it properly or have any Idea what causes this.
If you are still having this issue it may be caused by a problem like
Mismatching childNodes vs. VNodesin development that you didn’t control. For me was a vuetify’sv-btninside aptag. I changed the<p>for a<div>. And that made the favor.Also getting this error. Works fine on localhost but geneated files served from dist break. Error is totally random as I can do a build and sometimes the exact same code works
Same error for me also, it works perfectly on localhost but got occasionally Failed to execute ‘appendChild’ on ‘Node’ on server