title: Vite 'global is not defined'
body: <p>I'm creating a project using Vite with vanilla-ts, at one point I had to use the <code>readdir</code> method from the <code>fs-extra</code> package, but it created an error saying <code>process is not defined</code>, some suggested I place this code in my <code>vite-config.ts</code> file:</p>
  <pre class="lang-js prettyprint-override"><code>import { defineConfig } from 'vite'
  
  export default defineConfig({
    define: {
      'process.env': {}
    }
  })
  </code></pre>
  <p>That fixed the initial error but created a new one that read <code>global is not defined</code>, more research and by adding <code>'global': {}</code> on the <code>define</code> object, like before fixed the error but created another one saying <code>Cannot read properties of undefined (reading 'substr')</code></p>
  <p>Code used:</p>
  <pre class="lang-js prettyprint-override"><code>import { readdirSync } from 'fs-extra';
  
  const folders = readdirSync('./', { withFileTypes: true })
    .filter(dir =&gt; dir.isDirectory);
  </code></pre>
  <p>Vite version: ^2.9.5</p>
  <p>FS-Extra version: ^9.0.13</p>