in your example, you imported the API URL from .env, but it should be imported from config.js instead
const apiUrl = window.configs.VITE_LOCAL_API_URL;
https://wso2.com/choreo/docs/develop-components/develop-web-applications/build-and-deploy-a-single-page-web-application/#manage-runtime-configurations-for-web-applications