Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module not found: Can't resolve 'fs' #533

Open
julien51 opened this issue Apr 16, 2024 · 15 comments
Open

Module not found: Can't resolve 'fs' #533

julien51 opened this issue Apr 16, 2024 · 15 comments

Comments

@julien51
Copy link

  • I'm submitting a ...
    [X] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project

  • Summary

We used 3.17.4 without any issue. Recently we tried to upgrade to 3.27.2 in a nextjs application but we're now seeing the following error:

Module not found: Can't resolve 'fs'

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

Import trace for requested module:
../node_modules/brotli/compress.js
../node_modules/brotli/index.js
../node_modules/@uniswap/smart-order-router/build/module/util/gas-factory-helpers.js
../node_modules/@uniswap/smart-order-router/build/module/providers/eth-estimate-gas-provider.js
../node_modules/@uniswap/smart-order-router/build/module/providers/index.js
../node_modules/@uniswap/smart-order-router/build/module/index.js
../packages/unlock-js/dist/index.mjs
./src/components/interface/Authenticate.jsx
./src/components/interface/GlobalWrapper.tsx
./src/pages/_app.tsx
   automatically enabled Fast Refresh for 1 custom loader
   automatically enabled Fast Refresh for 1 custom loader
 ⨯ ../node_modules/brotli/build/encode.js:2:134
@gio-XD
Copy link

gio-XD commented Apr 18, 2024

I encountered this issue too, and I had to move the routing logic into the next API.

@julien51
Copy link
Author

julien51 commented Apr 22, 2024

On our end we want to keep it on the front-end...

@julien51
Copy link
Author

Event when adding the following to our next.js config:

  webpack: (config, { isServer }) => {
    // Fixes npm packages that depend on `fs` module (uniswap-router)
    if (!isServer) {
      config.resolve.fallback = {
        fs: false, // Exclude 'fs' module
      }
    }

we end up with a different error:
Screenshot 2024-04-22 at 9 00 02 AM

It looks like for some reason this dependency assumes the library is used on the backend.

Is there a way to make sure smart-order-router can also be used on front-end apps?

@julien51
Copy link
Author

It looks like the issue was introduced with 293b21e (which introduces brotli as a dep)

@julien51
Copy link
Author

julien51 commented May 2, 2024

@jsy1218 do you think you would accep a PR that replaces brotli with https://www.npmjs.com/package/brotli-wasm ?

@julien51
Copy link
Author

julien51 commented May 6, 2024

Or maybe @mikeki ?

@jsy1218
Copy link
Member

jsy1218 commented May 6, 2024

@julien51 will take a look. sorry for the trouble.

@julien51
Copy link
Author

julien51 commented May 8, 2024

@jsy1218 Thanks! Happy to help in any way I can! Thank you so much!

@yaseenmustapha
Copy link

yaseenmustapha commented May 15, 2024

@jsy1218
Running into this issue which seems to be related (was also introduced with 293b21e):
Screenshot_2024-05-15_at_2 35 11_PM

Preventing me from fetching Arbitrum prices in my project frontend.
Using React + Vite.

@soupydolph
Copy link

Experiencing the same issue.

NextJs app, error occurs when calling this:

const router = new AlphaRouter({
    chainId: 123 as ChainId,
    provider,
  });

Issue occurs whether I try to render client or server side.

Please fix, going to rollback to an earlier version and see if that resolves it.

@huntertdiamond
Copy link

Running into this issue which seems to be related (was also introduced with 293b21e):

yep, i downgraded to 3.20.1 and the issue was resolved in my next.js project.

Only problem now is that there is the gas issue on optimsim / base from #518

@julien51
Copy link
Author

@jsy1218 Is there anything we can do to help here?

@HugaidaS
Copy link

HugaidaS commented Jul 2, 2024

This is a real problem, it is just not compatible with modern tech stack, it is either a problem with ethers v6 or with this brotli issue, how we supposed to use this on the frontend...

@ScreenTechnicals
Copy link

Experiencing the same issue.

NextJs app, error occurs when calling this:

const router = new AlphaRouter({
    chainId: 123 as ChainId,
    provider,
  });

Issue occurs whether I try to render client or server side.

Please fix, going to rollback to an earlier version and see if that resolves it.

try to use this as AlphaRouterParams['chainId'] works fine:

const router = new AlphaRouter({
    chainId: 123 as AlphaRouterParams['chainId'],
    provider,
  });

@ScreenTechnicals
Copy link

  • I'm submitting a ...
    [X] bug report
    [ ] feature request
    [ ] question about the decisions made in the repository
    [ ] question about how to use this project
  • Summary

We used 3.17.4 without any issue. Recently we tried to upgrade to 3.27.2 in a nextjs application but we're now seeing the following error:

Module not found: Can't resolve 'fs'

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

Import trace for requested module:
../node_modules/brotli/compress.js
../node_modules/brotli/index.js
../node_modules/@uniswap/smart-order-router/build/module/util/gas-factory-helpers.js
../node_modules/@uniswap/smart-order-router/build/module/providers/eth-estimate-gas-provider.js
../node_modules/@uniswap/smart-order-router/build/module/providers/index.js
../node_modules/@uniswap/smart-order-router/build/module/index.js
../packages/unlock-js/dist/index.mjs
./src/components/interface/Authenticate.jsx
./src/components/interface/GlobalWrapper.tsx
./src/pages/_app.tsx
   automatically enabled Fast Refresh for 1 custom loader
   automatically enabled Fast Refresh for 1 custom loader
 ⨯ ../node_modules/brotli/build/encode.js:2:134

define this function in the server side,
in my case I'm using next js pages dir v14.x.x,
so I defined this inside src/pages/api/swap/route.api.ts file and it works!

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

No branches or pull requests

8 participants