reactjstypescriptvite

The requested module does not provide an export named 'default'


I am having some problems with the React project that I am currently working on. I use Vite as my build tool and for the last 2 or 3 days I see that sometimes I receive this error: Uncaught SyntaxError: The requested module '/src/Components/App/HamburgerMenu.tsx?t=1683406454267' does not provide an export named 'default' .

All my .tsx files have an exported default variable, and it works for every file most of the time, but sometimes I get this error, seemingly random. I cannot find a reason why it may happen but it can happen at any time when I save something in a file, it does not happen every time, just sometimes and it seems that for no reason, then it solves by itself after I save a few more times and/or I reload the page.

Edit: I am doing the imports and exports like this:

import Component from '../../Component'

and exporting

export default function Component () {...
}

Solution

  • I encountered a similar issue with the following error message: The requested module http://localhost:5173/node_modules/.vite/deps/... does not provide an export named ...

    This problem occurs because Vite caches dependencies in a .vite folder under node_modules.

    To resolve this:

    1. I deleted the .vite folder located in node_modules.
    2. Restarted the React app.

    This fixed the issue for me. I hope this helps