Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

'fs' must not be imported when in browser #80

Closed
anarkrypto opened this issue Feb 5, 2023 · 1 comment
Closed

'fs' must not be imported when in browser #80

anarkrypto opened this issue Feb 5, 2023 · 1 comment

Comments

@anarkrypto
Copy link

There doesn't seem to be any platform checking on the 'fs' import.

I am having the following error when running with Next.js: Module not found: Can't resolve 'fs'

The problem seems to have arisen with this commit, affecting the latest release of orbit-db in browser.
042ff1d

@haydenyoung

@anarkrypto
Copy link
Author

I just understand the problem better. In reality orbitdb already has a shim to avoid this: https://github.com/orbitdb/orbit-db/blob/main/src/fs-shim.js

But since it's executed before rendering, it will not works with React.

The solution a found on Next.js was adding this lines to next.config.js:

webpack: (config, { isServer }) => {
    
    // If client-side, don't polyfill `fs`
    if (!isServer) {
      config.resolve.fallback = {
        fs: false,
      };
    }
    return config;
  }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant