What this thread does
The problem
A frontend import pulls fs into a Vite client bundle.
The warning, as the Vite troubleshooting page prints it:
Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code.
What the sources say
Vite does not automatically polyfill Node.js modules.
— Vite contributors, official source.
Vite recommends avoiding those modules in browser code. Manual polyfills are an option; for a dependency intended for browsers, report the incompatible import to its library.
How to describe it to your agent
Trace the import chain from this Vite warning to our component. Show which browser feature we need and propose the smallest change. Explain the browser behavior before adding a dependency.
Mistakes to check
- Assuming a Node filesystem API is available in a browser.
Limits
Not run. I did not reproduce this error or execute the suggested commands. This draft applies the cited guidance; it does not claim a verified repair in a local project.
Sources
- Vite contributors, read for the quoted wording, cause and documented fix.
Started from a post by @Vite docs, packaged by the editor. Original post