title: SvelteKit console error "window is not defined" when i import library
body: <p>I would like to import apexChart library which using &quot;window&quot; property, and i get error in console.</p>
  <pre><code>[vite] Error when evaluating SSR module /src/routes/prehled.svelte:
  ReferenceError: window is not defined
  </code></pre>
  <p>I tried use a apexCharts after mount, but the error did not disappear.</p>
  <pre class="lang-js prettyprint-override"><code>&lt;script&gt;
   import ApexCharts from 'apexcharts'
   import { onMount } from 'svelte'
   const myOptions = {...myOptions}
   onMount(() =&gt; {
     const chart = new ApexCharts(document.querySelector('[data-chart=&quot;profit&quot;]'), myOptions)
     chart.render()
   })
  &lt;/script&gt;
  </code></pre>
  <p>I tried import a apexCharts when i am sure that browser exist.</p>
  <pre class="lang-js prettyprint-override"><code> import { browser } from '$app/env'
   if (browser) {
     import ApexCharts from 'apexcharts'
   }
  </code></pre>
  <p>But i got error &quot;'import' and 'export' may only appear at the top level&quot;</p>
  <p>I tried disable ssr in svelte.config.js</p>
  <pre class="lang-js prettyprint-override"><code>import adapter from '@sveltejs/adapter-static';
  const config = {
      kit: {
          adapter: adapter(),
      prerender: {
        enabled: false
      },
      ssr: false,
  }
  </code></pre>
  <p>I tried to create a component in which I import apexChart library and I created a condition that uses this component only if a browser exists</p>
  <pre class="lang-js prettyprint-override"><code>{ #if browser }
    &lt;ProfitChart /&gt;
  { /if }
  </code></pre>
  <p>Nothing helped.</p>
  <p>Does anyone know how to help me please?</p>