webpack 5 & next.js 10 - how to add resolve fallback to config

Marcin Wosinek - May 15 '21 - - Dev Community

Have you ever got:


    error - <some-3rd-party-lib>:0

    Module not found: Can't resolve 'fs' // or process, Buffer, etc.

Enter fullscreen mode Exit fullscreen mode

error in your nextjs app; and the all the solutions on stack overflow were pointing to something like:

// webpack.config.js
{
  resolve: {
        fallback: { "fs": false }
  }
}
Enter fullscreen mode Exit fullscreen mode

when you didn't even have webpack.config.js?

Quick solution

It's all because nextjs is hiding its webpack configuration. It's simplifying for most use cases, but a bit of a pain in some others. The quick solution for it is to this into next.config.js:

module.exports = {
  future: {
    webpack5: true,
  },
  webpack: (config) => {
    config.resolve.fallback = { fs: false };

    return config;
  },
};
Enter fullscreen mode Exit fullscreen mode

Longer overview

Links

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player