Skip to content

πŸ› Bug: Vite Internal Server Error – await Used Outside async FunctionΒ #135

Closed

Description

@abhishek-nexgen-dev

While running the frontend development server using Vite, the application crashes with an internal server error related to incorrect usage of await.

The error indicates that await is being used outside of an async function, which is not allowed in regular function scopes in TypeScript/JavaScript.


❌ Error Message

[vite] Internal server error: `await` is only allowed within async functions and at the top levels of modules
Plugin: vite:oxc
File: src/shared/component/v1/LoginPage.tsx:80:23
const response = await apiService.login(email, password)

πŸ“‚ Affected File

src/shared/component/v1/LoginPage.tsx

Line: ~80


πŸ” Root Cause (Expected)

The await keyword is used inside a function that is not marked as async, or it is placed directly inside a React component body instead of an event handler or effect.

Common causes:

  • await used directly inside a React component body
  • await used inside a normal function instead of an async function
  • Missing async keyword on a handler like handleLogin

βœ… Expected Behavior

  • The login API call should execute inside an async function
  • The Vite dev server should start without crashing
  • Login flow should work correctly

πŸ› οΈ Suggested Fix

Wrap the await call inside an async function, for example:

const handleLogin = async () => {
  try {
    const response = await apiService.login(email, password)
    if (!response.success) {
      // handle error
    }
  } catch (error) {
    console.error(error)
  }
}

And call it from an event handler:

<button onClick={handleLogin}>Login</button>

πŸ”„ Steps to Reproduce

  1. Clone the repository

    git clone <repo-url>
  2. Install dependencies

    pnpm install
  3. Start the dev server

    pnpm dev
  4. Observe the Vite internal server error


🧩 Environment

  • Framework: React + TypeScript
  • Bundler: Vite
  • Package Manager: pnpm
  • OS: Linux
Image

Activity

  1. github-actions commented on Jan 12, 2026

    @github-actions

    Thank you for raising this issue!

    We'll review it as soon as possible. We truly appreciate your contributions! ✨

    Meanwhile make sure you've visited the README.md, CONTRIBUTING.md, and CODE_OF_CONDUCT.md before creating a PR for this. Also, please do NOT create a PR until this issue has been assigned to you. 😊

  2. abhishek-nexgen-dev commented on Jan 12, 2026

    @abhishek-nexgen-dev
    MemberAuthor

    @Rohanrathod7 Do you want to fix this

  3. euzghe commented on Jan 12, 2026

    @euzghe
    Contributor

    Hi! I'm a senior software engineering student. I've noticed the Vite internal server error regarding the await usage. I would like to fix this bug. Could you please assign it to me?

  4. Rohanrathod7 commented on Jan 12, 2026

    @Rohanrathod7
    Contributor

    I would love to but if @euzghe can solve it today itself you can assign him

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions