Kevin
Kevin

Reputation: 1367

Can't resolve 'fs' when using Instascan in Next js project

I'm trying to use Instascan in my Next JS project, but I'm getting an error Module not found: Can't resolve 'fs' in '/node_modules/instascan/src'. I'm assuming this has to do with SSR. I tried to set the webpack config using the next.config.js file based on this comment:

module.exports = {
    webpack: (config) => {
        return Object.assign({}, config, {
            node: {
                fs: 'empty'
            }
        })
    },
};

But that doesn't seem to work either, I assume because that webpack config is for the client side? I've read that people also bundle their server using webpack, not 100% sure if that's the case with next, also not sure if that would fix anything. Anyone who can guide me into some sort of solution here? Not really sure how I can advance anymore.

Upvotes: 2

Views: 1290

Answers (1)

Kevin
Kevin

Reputation: 1367

I honestly don't see the difference, but using a spread operator seems to fix it?

module.exports = {
  webpack: (config) => {
    return {
      ...config,
      node: {
        fs:
          'empty'
        }
      }
   }
};

Now I'm getting an Instascan-specific issue, so this is closed.

Upvotes: 1

Related Questions