简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM