title: Vite Error only in build (TypeError: Cannot read property 'insertBefore' of null)
body: <p>I created a Vite frontend with Vue3 and TailwindCss.
  Starting the application with <code>npm run serve</code>: everything works fine without any warnings or errors.</p>
  <p>But after a deployment with <code>npm run build</code> I get <code>TypeError: Cannot read property 'insertBefore' of null</code> errors when filtering or selecting items of arrays/objects.</p>
  <p><strong>Link to the repo with all the code:</strong> <a href="https://github.com/mschoeffel/vite-build-error" rel="nofollow noreferrer">Github Repo</a></p>
  <p><strong>Here a link to the deployed application:</strong> <a href="https://votox.mschoeffel.de" rel="nofollow noreferrer">Deployed Application</a></p>
  <p><strong>Steps to reproduce:</strong></p>
  <ol>
  <li>Pull Github Repo</li>
  <li>Start with either <code>npm run serve</code> to see how it should work. Or deploy the <code>dist</code> directory after <code>npm run build</code> to any webserver like nginx to get the errors.</li>
  <li>Open in browser <code>localhost:3000</code> or the URL of the webserver or my deployed link.</li>
  <li>Log in via Username <code>John.Doe@mail.com</code> - Password: <code>test123</code></li>
  <li>Navigate to <code>/apartments</code> or with the navigation bar on the left side <code>Wohnungen</code>.</li>
  <li>Error 1: Select an apartment from the list and click on it again to deselect it. -&gt; Now no apartment can be selected anymore and the error appears in the console. Reload is required to get it  working again. (Switching from one apartment to the other works fine. The error only occurrs if deselecting the currently selected apartment)</li>
  <li>Error 2: If inputting something into the search input at the top of the same page the apartments get filtered accordingly(eg. enter <code>Rund</code>) if then removing the searchinput all apartments appear again. But if you select one apartment of the filtered list and the remove the searchinput you get errors and the list doesn't get updated.</li>
  </ol>
  <p><strong>Code reference:</strong><br />
  All the described functionality happens in: <a href="https://github.com/mschoeffel/vite-build-error/blob/main/src/views/Apartments.vue" rel="nofollow noreferrer">Appartment View</a></p>
  <ul>
  <li>selecting/deselecting:
  <ul>
  <li>Function: <code>selectWohnung()</code> (<a href="https://github.com/mschoeffel/vite-build-error/blob/3f0797f4e0f2a8d2641df6f5bf0366a853b56bec/src/views/Apartments.vue#L273" rel="nofollow noreferrer">Line 273</a>)</li>
  <li>Components: <code>ApartmentListItemComponent</code>(ListObject) <code>ApartmentDetailComponent</code>(DetailObjectView)</li>
  <li>Data: <code>apartments</code>(List of all apartments), <code>filteredApartments</code>(Filtered list of all apartments), <code>selectedApartment</code>(The current selected apartment)</li>
  </ul>
  </li>
  <li>filtering:
  <ul>
  <li>Function: <code>search()</code> (<a href="https://github.com/mschoeffel/vite-build-error/blob/3f0797f4e0f2a8d2641df6f5bf0366a853b56bec/src/views/Apartments.vue#L329" rel="nofollow noreferrer">Line 329</a>)</li>
  <li>Components: <code>ApartmentListItemComponent</code>(ListObject)</li>
  <li>Data: <code>apartments</code>(List of all apartments), <code>filteredApartments</code>(Filtered list of all apartments), <code>searchString</code>(Search input)</li>
  </ul>
  </li>
  </ul>
  <p><strong>My thoughts/tries:</strong></p>
  <ul>
  <li>I have no idea how it can work in <code>serve</code> absoluteley fine but after <code>build</code> it throws errors...</li>
  <li>I think it has something to do with <code>v-if</code>. E.g. I switched from:<code>&lt;aside v-if=&quot;selectedApartment !== undefined&quot;&gt;[...]</code> to <code>&lt;aside v-show=&quot;selectedApartment !== undefined&quot;&gt;[...]</code> to fix the select apartment errors. But I don't think I solved the main problem with this workaround -&gt; Reverted in Repo.</li>
  <li>On mobile none of the errors occurr. So maybe it has to do something with the visibility of components?</li>
  </ul>
  <p><strong>I hope these information are enough and not too messy. I wanted to keep the code exactly as deployed. I have no futher idea how to fix this error or where this error comes from. Thanks in advance.</strong></p>
  <p>Additional information:</p>
  <ul>
  <li>Node version: 14.17.3</li>
  <li>npm version: 7.19.1</li>
  <li>Browser: Chrome version 91.0.4472.124</li>
  <li>Deployed with <a href="https://github.com/mschoeffel/vite-build-error/blob/main/public/.htaccess" rel="nofollow noreferrer">.htaccess</a></li>
  </ul>