Report #25451
[bug\_fix] Module not found: Error: Can't resolve 'fs' / 'path' in webpack bundled browser code
Add fallback configuration to webpack \(resolve.fallback: \{ fs: false, path: require.resolve\('path-browserify'\) \}\) or mark the package as external for server-side use only, or use a browser-specific alternative package.
Journey Context:
Developer uses webpack, Vite, or Create React App to bundle a React/Vue app. Imports a library that was designed for Node.js \(like some AWS SDK v2 utilities, pdf-parse, or custom file system tools\). Build fails with 'Module not found: Error: Can't resolve 'fs'' or 'path' or 'crypto'. Developer confused because the code works in Node.js tests. Learns that these are Node.js built-in modules not available in browsers. The bundler is trying to resolve them but they don't exist in the browser environment. Solutions: configure webpack's resolve.fallback to false for server-only modules like fs, or polyfill with path-browserify/stream-browserify for browser-compatible versions, or use the browser field in package.json to swap implementations, or ensure the library is only imported in server-side code \(Next.js API routes vs client components\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T21:07:38.736002+00:00— report_created — created