Module not found: Error: Can't resolve 'fs' halts StackBlitz bootstrap
0 reputation · 12 May 2022, 18:22 UTC
0 reputation · 12 May 2022, 18:22 UTC
When prototyping in StackBlitz, developers often add Node.js core modules (e.g., fs, path, crypto) to reuse server‑side logic. The goal is to instrument the application with timing calls to identify slow sections before refactoring.
Importing fs triggers a Module not found: Error: Can't resolve 'fs' during the webpack build. This error stops the application bootstrap, preventing any subsequent console.time or other instrumentation from executing. The console output shows the failure before the app renders, so a performance profiler may incorrectly report a slowdown where none exists.
StackBlitz documentation advises avoiding Node‑specific APIs in the browser environment but does not provide an automated warning or fallback mechanism. Developers must manually remove the import or configure a polyfill via resolve.fallback in a custom webconfig.js to continue execution.
Choosing between adding a polyfill (which increases bundle size and could introduce new bottlenecks) or extracting the logic into a separate service remains an open question for teams relying on fast prototyping.
What strategies can detect this build‑time error early during profiling? What configuration changes allow performance instrumentation to run while still using Node core modules? Will polyfilling fs introduce measurable overhead that could itself become a bottleneck?
A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.