title: How can I do top level await
body: <p>I am trying to build a react app and want to call a function like this:</p>
  <pre><code>if (typeof window !== 'undefined') { var token = (await getItem('secure_token')); }
  if (typeof window !== 'undefined') { var user_id = (await getItem('user_id')); }
  </code></pre>
  <p>I am getting error that:</p>
  <pre><code>Module parse failed: The top-level-await experiment is not enabled (set experiments.topLevelAwait: true to enabled it)
  </code></pre>
  <p>How can I achieve that. because without await, I am getting  <code>[object Promise]</code> and not the actual value.</p>
  <p>Below is the complete code:</p>
  <pre class="lang-js prettyprint-override"><code>import axios from &quot;axios&quot;;
  import { getStorage } from &quot;../../components/Helper&quot;;
  const API_URL = &quot;http://127.0.0.1:8000/api&quot;;
  const BASE_API = &quot;http://127.0.0.1:8000&quot;;
  var token = null;
  var user_id = null;
  if (typeof window !== 'undefined') { var token = (await getItem('secure_token')); }
  if (typeof window !== 'undefined') { var user_id = (await getItem('user_id')); }
  export const API_ROUTE = axios.create({
      baseURL: API_URL,
      withCredentials: true,
      crossdomain: true,
      headers: {
          &quot;Key&quot;: token,
          &quot;Id&quot;: user_id
      }
  });
  
  export const csrf_token = async () =&gt; {
      await axios.get(BASE_API + '/sanctum/csrf-cookie');
  }
  
  async function getItem(item) {
      var data = await getStorage(item);
      return data;
  }
  </code></pre>