Fix “Module not found: Can't resolve encoding” in Next.js

By

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-fetch dependency tree. Current Next.js versions use the platform fetch() API, so first update the package that imports old node-fetch and 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.

Tagged: Next.js · All topics

Want me to talk about your product? You can sponsor this site.

~~~

Related posts about next: