Vite externalized a Node.js module for browser compatibility
Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code.
Vite detected Node.js-only module usage in browser code and externalized it instead of bundling it into the client build.
Module "fs" has been externalized for browser compatibility.build errors
Observed message
Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code.
Why it happens
Browser code imports a Node.js built-in module like `fs` or `path`.
A third-party dependency intended for Node.js is being bundled into the client.
Server-only logic was accidentally moved into shared frontend code.
How to fix it
Read the module named in the warning, such as `fs`, then trace the imports from the browser entry point until you find the Node-only dependency.
If browser code imports `fs.readFile` to open a user's file, use a file input and the browser File API instead. To read a server file, expose only the needed data through an API.
If a third-party package brings in the module, check whether it has a supported browser build or separate browser package. Update the client import to that entry point.
Keep server-only helpers out of frontend imports, including shared index files that re-export backend modules. Splitting client and server modules prevents accidental bundling.
Do not solve this by marking `fs` external in Vite: the browser still has no Node filesystem API. Run the affected feature in the browser and a production build to confirm the warning and runtime failure are gone.