Fix “Module not found: Can't resolve encoding” in Next.js
By Flavio Copes
Fix the 'Module not found: Can't resolve encoding' error in Next.js, coming from node-fetch, by running npm install encoding to add the missing package.
This fixes one legacy
node-fetchdependency tree. Current Next.js versions use the platformfetch()API, so first update the package that imports oldnode-fetchand inspect why server-only code is entering the client bundle.
I ran into this error in a Next.js application:
Module not found: Can’t resolve ‘encoding’ in …/node_modules/node-fetch/lib’
To fix this, I ran npm install encoding and the error was gone!
Treat that installation as a compatibility workaround, not a general Next.js fix. Check the import trace in the build error before adding a transitive dependency to your application.
Want me to talk about your product? You can sponsor this site.
Related posts about next: