skip to Main Content

im using react & ts & vite combo, I encounter a problem where when I run

npm run dev 

I get the following error:

The requested module ‘/src/components/ui/index.ts’ does not provide an export named ‘SquareButton’

This is my index.ts file:


export * from "./input";
export * from "./button";
export * from "./checkbox";
export * from "./phone-input";
export * from "./separator";
export * from "./select";
export * from "./label";
export * from "./otp";
export * from "./date-picker";
export * from "./time-picker";

And this is the import:

import { SquareButton } from "@components/ui";

I found a way to temporary fix is, and it’s by simply swapping lines in the index.ts file, for exmaple I move line 10 to line 9, and line 9 to line 10, this problem is really weird since my ts path alias obviously is working, it’s like vite doesn’t seem to know that the file exists until I update it, first time ever encountering this problem.

2

Answers


  1. Chosen as BEST ANSWER

    That's kind of funny, but clearing the chrome cache and doing hard reload solved the problem


  2. The error you’re encountering typically happens when Vite doesn’t properly recognize the exports during its initial build. This can be due to Vite’s aggressive caching or a temporary issue with module resolution.

    Double-check that SquareButton is indeed exported from the correct module, likely within ./button or another relevant file.

    Try clearing Vite’s cache by deleting the .vite directory (usually found in node_modules) and then rerun the development server:

    run the commands below

    rm -rf node_modules/.vite
    npm run dev
    

    Alternatively, try running Vite with the –force flag to force cache invalidation:

    npm run dev -- --force
    

    Verify that your TypeScript path aliases in tsconfig.json or vite.config.ts are correctly set up and point to the right directories.

    Ensure you’re using the correct Vite plugins for TypeScript, which might help in resolving such issues.

    If the problem persists after these steps, consider reporting it as a potential bug with a minimal reproducible example to the Vite team.

    Here is Vite’s GitHub repo

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search