cosmology-tech / cosmos-kit

Universal wallet connector for the Cosmos ⚛️
https://cosmology.zone/products/cosmos-kit
BSD 3-Clause Clear License
183 stars 129 forks source link

@cosmos-kit/react - Module not found: Can't resolve 'fs' #237

Closed abigpotostew closed 1 year ago

abigpotostew commented 1 year ago

Using next js, copied over the code from a template I get this error on verion

Using the latest version 1.3.33-prerelease.1 I see

Module not found: Can't resolve 'fs'

Import trace for requested module:
../../node_modules/@cosmos-kit/react/dist/index.js
./pages/_app.tsx

Using older version, v1.3.12+ I get a slightly different error:

Module not found: Can't resolve 'fs'

Import trace for requested module:
../../node_modules/@cosmos-kit/keplr-extension/dist/index.js
../../node_modules/@cosmos-kit/keplr/dist/index.js
./pages/_app.tsx

1.3.11 is the last version that works for me.

Jorah-M commented 1 year ago

Having kind of the same issue.

./node_modules/@cosmos-kit/react/node_modules/@cosmos-kit/core/dist/index.js:11570:0
Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@cosmos-kit/react/module/provider.js
./node_modules/@cosmos-kit/react/module/index.js
./pages/_app.tsx

Even if you rollback to prev versions - error occurs anyway.

twhy commented 1 year ago

@abigpotostew Thanks for reporting the issue. Do you mind pushing the code to github and send us a link. So I can test it out to see what's wrong ?

pyramation commented 1 year ago

hey @Jorah-M and @abigpotostew you realize that you're using the prerelease? Are you intending to do this?

abigpotostew commented 1 year ago

@abigpotostew Thanks for reporting the issue. Do you mind pushing the code to github and send us a link. So I can test it out to see what's wrong ?

You can clone this https://github.com/abigpotostew/microcosmbot and run yarn dev from apps/web package and navigate to localhost:3000 in your browser. You will see the error immediately.

hey @Jorah-M and @abigpotostew you realize that you're using the prerelease? Are you intending to do this?

I've tried several versions between v1.3.12 and 1.3.32 and all have similar errors. I found that v1.3.12 works because that is was is setup in the code templates.

abigpotostew commented 1 year ago

I got a version working now. Here's the versions of libraries I'm using:

- "@cosmos-kit/core": "1.3.0",
- "@cosmos-kit/cosmostation": "0.15.13",
- "@cosmos-kit/keplr": "0.33.13",
- "@cosmos-kit/leap": "0.14.12",
- "@cosmos-kit/react": "1.3.11",
- "@keplr-wallet/cosmos": "^0.12.9",
+ "@cosmos-kit/core": "1.6.0",
+ "@cosmos-kit/cosmostation": "0.15.37",
+ "@cosmos-kit/keplr": "0.33.39",
+ "@cosmos-kit/react": "1.3.31",
+ "@cosmos-kit/walletconnect": "0.3.16",
+ "@keplr-wallet/cosmos": "0.12.11",
twhy commented 1 year ago

@abigpotostew I can't run your code because it requires some private packages. Based on the error Module not found: Can't resolve 'fs' Maybe you can try update your next.config.js

module.exports = {
  reactStrictMode: true,
  transpilePackages: ['@nouns-stream/ui', '@microcosms/bot', '@microcosms/db'],
  webpack(config, { isServer }) {
    if (!isServer) {
      config.resolve.fallback = {
        fs: false
      }
    }
    config.module.rules.push({
      test: /\.svg$/i,
      issuer: { and: [/\.(js|ts|md)x?$/] },
      use: ['@svgr/webpack'],
    })
    return config
  },
}
twhy commented 1 year ago

I tried creating a new project with create-cosmos-app and upgrade @cosmos-kit/react to version 1.3.32. And it works fine.

npm install -g create-cosmos-app
cca --name send-example --example --template send-tokens

I'm glad that you got a version working for you. And if you can provide a minimum codebase that can reproduce the error. Please send it to us. Thanks. @abigpotostew

@Jorah-M Can you upload a minimum codebase to github that can reproduce the error ? Thanks!

Jorah-M commented 1 year ago

It seems to work when I changed the version to 1.3.32 and deleted old node_modules. I got a private repo with some packages as well, so I'm afraid I can't reproduce it somewhere.

twhy commented 1 year ago

@Jorah-M That's great! If you find any more issues, feel free to submit to us. Thanks!

abigpotostew commented 1 year ago

Same here, I am not able to reproduce it reliably. Since I found a working version, I will close this issue. Thanks.