Angular 12 – Fixing Module not found: Error: Can’t resolve ‘fs’

Let’s fix the error as shown in the title. I assume you’re using Angular 12+ where some whatever changes with polyfills removals from the update somehow led to fs magically missing, thus your packages such as mediainfo fails to build since it depends on fs.

To start, install fs-web by doing npm install fs-web

Then go to your file named and update the file with these

  "extends": "./tsconfig.json",
  "compilerOptions": {
    "paths": {
      "fs": ["./node_modules/fs-web"]

Restart your angular serve.

The above is how I fixed mine. The idea is, for whatever “cannot import module” whatever error that shows, it’s possible the package is a node-specific package, and thus isn’t available for the browser, after the polyfills were dropped.

Thus, search if you’ll find a “browser-fied” version of the package of error, install it, then make an explicit pointing to this alternative package, but with same name, in this case, "fs"

I hope this helps you. Hope to see you in the next one.

Related Articles

Back to top button