Error AtlasError Documentation and Resolution

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
Module "fs" has been externalized for browser compatibility. Cannot access "fs.readFile" in client code.
  • 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.
  1. Remove Node.js built-ins from code that runs in the browser.
  2. Move server-only logic behind an API or server runtime boundary.
  3. Follow the import chain from the browser entry point to the Node-only import. If a dependency brings it in indirectly, check whether that package documents a browser entry point or a separate browser-compatible package.
  4. For example, a browser cannot use fs.readFile to read a server's local file. Read it in your backend and return the permitted data through an API, or let the user select a local file with a file input and the browser File API.
  5. Keep server helpers out of shared barrel exports consumed by client code. Import browser-safe utilities directly when a shared index also exposes backend dependencies.
  6. Do not add fs to build external settings as a fix: leaving an import external does not give the browser a filesystem. Consider a polyfill only for APIs that can actually be implemented in the browser.
  7. Run the development page and a production build preview after the change. Exercise the feature that used the dependency and confirm the externalized-module warning and runtime failure are gone.
Vite: Troubleshooting
Vite module externalized for browser compatibility: causes and fixes | Error Atlas