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

Сan't integrate widget #580

Open
Doberman2029 opened this issue Apr 24, 2023 · 27 comments
Open

Сan't integrate widget #580

Doberman2029 opened this issue Apr 24, 2023 · 27 comments
Labels
bug Something isn't working

Comments

@Doberman2029
Copy link

Bug Description
Dependency (modules) error when using widget

Steps to Reproduce

  1. Create next project using next@12.1.5
  2. Install latest @uniswap/widgets and react-redux
  3. Integrate SwapWiget to page
  4. An error has occurred

Expected Behavior
The widget must be on the page, the project must be compiled successfully

Additional Context
image
Problem with module \node_modules@uniswap\conedison\dist\provider\signing

@Doberman2029 Doberman2029 added the bug Something isn't working label Apr 24, 2023
@WyattMufson
Copy link

Getting the same issue

@celsosa
Copy link

celsosa commented Apr 28, 2023

same here

@10xdegen
Copy link

same

1 similar comment
@Gabalyno
Copy link

same

@cawabunga
Copy link

You need to transpile @uniswap/widgets, I'm not sure how to do it in 12 version, but in 13 version there is an option in next.config.js file (link to doc):

 module.exports = {
   ...
   transpilePackages: ['@uniswap/widgets']
};

@WyattMufson
Copy link

Seeing this same issue in a React app using webpack

@Doberman2029
Copy link
Author

You need to transpile @uniswap/widgets, I'm not sure how to do it in 12 version, but in 13 version there is an option in next.config.js file (link to doc):

 module.exports = {
   ...
   transpilePackages: ['@uniswap/widgets']
};

Unfortunately after transpile the package still shows the same error

@cawabunga
Copy link

cawabunga commented May 12, 2023

You need to transpile @uniswap/widgets, I'm not sure how to do it in 12 version, but in 13 version there is an option in next.config.js file (link to doc):

 module.exports = {
   ...
   transpilePackages: ['@uniswap/widgets']
};

Unfortunately after transpile the package still shows the same error

That's unfortunate. I bumped into the same issue that transpiling @uniswap/widgets does not help, so I had to transpile problematic @uniswap/conedison too. Hope it will help you as well.

@intertwine
Copy link

To make the above comment from @cawabunga explicit, what worked for me was:

In next.config.js:

module.exports = {
    ...
    transpilePackages: ['@uniswap/widgets', '@uniswap/conedison'],
};

(Using nextjs@13.4, @uniswap/widgets@2.51.2 & node@18)

Before applying the fix above, @uniswap/widgets@2.24.0 was the latest version I could use to build without the @uniswap/conedison errors.

@Doberman2029
Copy link
Author

@intertwine @cawabunga Thanks, this solved the problem with @uniswap/conedison. But after that another error appeared.
image
It all refers to this code
image

@cawabunga
Copy link

@Doberman2029 Not sure if it is still relevant. But it looks like you call react hook outside a render function.

@WyattMufson
Copy link

Anyone know the equivalent of this for webpack projects?

@Doberman2029
Copy link
Author

@cawabunga Yeah it's relevant. Problem happen only when widget integrated. So it's problem with hooks inside the package

@nickfujita
Copy link

nickfujita commented May 31, 2023

Unfortunately, not using nextJS for a project that's using the widget, and the webpack alias did not resolve the issue. So I created a fork branch with the functions of @uniswap/conedison just moved into this repos utils folder, and the issue was resolved. I also ran into the the Cannot read properties of null (reading 'useState') when using yarn link to reference my local branch, but when referencing the branch from github the error appears to be gone.

Since it's not a long term solution to keep a fork updated with conedison functions copied over, to this repo, I looked more into what other repos are using @uniswap/conedison, and aside from the forks of this repo it doesn't seem that it's being used by any other uniswap hosted repo? At least the ones publically available. There is one other project, Wido that is also a fork of this repo, but just a repurposed version of this repo.

Repos using @uniswap/conedison

If there aren't any other repos using the utils in conedison for a purpose other than forks of this widget, can the util functions just be pulled into the utils folder in this repo?

Created this tentative PR for the changes:
#589

@lbennett-stacki
Copy link

If adding both transpiles, get the following

./node_modules/@uniswap/widgets/node_modules/@web3-react/core/dist/index.js
Module parse failed: Cannot use 'import.meta' outside a module (58:16)
|                 // still a Refresh Boundary later.
|                 // @ts-ignore importMeta is replaced in the loader
>                 import.meta.webpackHot.accept();
|                 // This field is set when the previous version of this module was a
|                 // Refresh Boundary, letting us know we need to check for invalidation or

@ryuzaki01
Copy link

I have forked this package published it under the name @nftearth/uniswap-widget and make it work for NextJS
also you don't need to install react-redux, I have reworked it so it will use React Context Instead

I hope it helps

https://github.com/NFTEarth/uniswap-widgets
https://www.npmjs.com/package/@nftearth/uniswap-widgets

@wojakpepechad
Copy link

To make the above comment from @cawabunga explicit, what worked for me was:

In next.config.js:

module.exports = {
    ...
    transpilePackages: ['@uniswap/widgets', '@uniswap/conedison'],
};

(Using nextjs@13.4, @uniswap/widgets@2.51.2 & node@18)

Before applying the fix above, @uniswap/widgets@2.24.0 was the latest version I could use to build without the @uniswap/conedison errors.

This is the only thing that worked for me, thanks!

@compojoom
Copy link

compojoom commented Feb 2, 2024

For those here using nextjs v13 and pulling their hairs.
After installing the widget I was getting:

./node_modules/brotli/build/encode.js:2:134
Module not found: Can't resolve 'fs'

This was resolved by adding this to my nest config:

    config.resolve.fallback = {
    ...config.resolve.fallback,
        fs: false, // needed for uniswap widget
    } 

The resolve option allows you to specify replacements for built-in Node.js modules that are not available or do not work in the browser environment. This is necessary because the fs module is not available in the browser enviroment. So anything in uniswap that tries to import the fs module will receive an empty module instead.

After that the only way to get the widget to render is to disable SSR for the it. You can load it like this:

const Widget = dynamic(() => {
  return import('@uniswap/widgets').then((mod) => mod.SwapWidget)
}, { ssr: false })

@M-Afzaal-Afzal
Copy link

@compojoom i am using next.js 14. I followed the instrunctions you gave but i'm getting the following error

Error: failed to fetch list: https://gateway.ipfs.io/ipns/tokens.uniswap.org

@fabdarice
Copy link

If adding both transpiles, get the following

./node_modules/@uniswap/widgets/node_modules/@web3-react/core/dist/index.js
Module parse failed: Cannot use 'import.meta' outside a module (58:16)
|                 // still a Refresh Boundary later.
|                 // @ts-ignore importMeta is replaced in the loader
>                 import.meta.webpackHot.accept();
|                 // This field is set when the previous version of this module was a
|                 // Refresh Boundary, letting us know we need to check for invalidation or

Has anyone found a way to fix this?

@vladimirperju
Copy link

any ideas for this issue? (next 14 without ts)
Module not found: Can't resolve 'fs'

@daniiba
Copy link

daniiba commented Apr 16, 2024

any ideas for this issue? (next 14 without ts) Module not found: Can't resolve 'fs'

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack: (config) => {
    config.resolve.fallback = { fs: false };

    return config;
  },
};
export default nextConfig;

That fixed it for me

@TwilightLogic
Copy link

TwilightLogic commented Apr 27, 2024

Error: failed to fetch list: https://gateway.ipfs.io/ipns/tokens.uniswap.org

How can I fix it? ☹️

My part of package.json:

{
  "dependencies": {
    "@headlessui/react": "^1.7.19",
    "@headlessui/tailwindcss": "^0.2.0",
    "@uniswap/sdk-core": "^4.2.1",
    "@uniswap/v2-sdk": "^4.3.0",
    "@uniswap/v3-sdk": "^3.11.0",
    "@uniswap/widgets": "^2.59.0",
    "@web3-react/core": "^8.2.3",
    "next": "14.2.2",
    "react": "^18",
    "react-dom": "^18",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.2",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

@SonOfCrypto
Copy link

Error: failed to fetch list: https://gateway.ipfs.io/ipns/tokens.uniswap.org

How can I fix it? ☹️

My part of package.json:

{
  "dependencies": {
    "@headlessui/react": "^1.7.19",
    "@headlessui/tailwindcss": "^0.2.0",
    "@uniswap/sdk-core": "^4.2.1",
    "@uniswap/v2-sdk": "^4.3.0",
    "@uniswap/v3-sdk": "^3.11.0",
    "@uniswap/widgets": "^2.59.0",
    "@web3-react/core": "^8.2.3",
    "next": "14.2.2",
    "react": "^18",
    "react-dom": "^18",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.2",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

when you open https://gateway.ipfs.io/ipns/tokens.uniswap.org in the browser you will be redirected to https://ipfs.io/ipns/tokens.uniswap.org

for me the new url works

<SwapWidget tokenList={'https://ipfs.io/ipns/tokens.uniswap.org'} />

@terry-daviass
Copy link

terry-daviass commented May 2, 2024

Good day!
I have and issue with polyfills and fs as mentioned in this post with create-react-app:

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
- install 'stream-http'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "http": false }

ERROR in ./node_modules/@uniswap/smart-order-router/build/module/providers/tenderly-simulation-provider.js 2:0-26
Module not found: Error: Can't resolve 'https' in '/home/qt/Projects/Crypto/uniswap-test/node_modules/@uniswap/smart-order-router/build/module/providers'

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.

If you want to include a polyfill, you need to:
- add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
- install 'https-browserify'
If you don't want to include a polyfill, you can use an empty module like this:
resolve.fallback: { "https": false }

ERROR in ./node_modules/brotli/build/encode.js 23:11-24
Module not found: Error: Can't resolve 'fs' in '/home/qt/Projects/Crypto/uniswap-test/node_modules/brotli/build'

webpack compiled with 3 errors and 202 warnings

So I have tried to follow the instructions and created webpack.config.js like that:

module.exports = {
    resolve: {
        fallback: {
            "fs": false,
            "http": require.resolve("stream-http"),
            "https": require.resolve("https-browserify"),
        }
    }
};

In root directory of my project, but nothing helped. Anyone faced with this issue before? What actually helped is this case?

@KoneeVibes
Copy link

Good day! I have and issue with polyfills and fs as mentioned in this post with create-react-app:

BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
This is no longer the case. Verify if you need this module and configure a polyfill for it.
If you want to include a polyfill, you need to:

  • add a fallback 'resolve.fallback: { "http": require.resolve("stream-http") }'
  • install 'stream-http'
    If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "http": false }
    ERROR in ./node_modules/@uniswap/smart-order-router/build/module/providers/tenderly-simulation-provider.js 2:0-26
    Module not found: Error: Can't resolve 'https' in '/home/qt/Projects/Crypto/uniswap-test/node_modules/@uniswap/smart-order-router/build/module/providers'
    BREAKING CHANGE: webpack < 5 used to include polyfills for node.js core modules by default.
    This is no longer the case. Verify if you need this module and configure a polyfill for it.
    If you want to include a polyfill, you need to:
  • add a fallback 'resolve.fallback: { "https": require.resolve("https-browserify") }'
  • install 'https-browserify'
    If you don't want to include a polyfill, you can use an empty module like this:
    resolve.fallback: { "https": false }
    ERROR in ./node_modules/brotli/build/encode.js 23:11-24
    Module not found: Error: Can't resolve 'fs' in '/home/qt/Projects/Crypto/uniswap-test/node_modules/brotli/build'
    webpack compiled with 3 errors and 202 warnings

So I have tried to follow the instructions and created webpack.config.js like that:

module.exports = {
    resolve: {
        fallback: {
            "fs": false,
            "http": require.resolve("stream-http"),
            "https": require.resolve("https-browserify"),
        }
    }
};

In root directory of my project, but nothing helped. Anyone faced with this issue before? What actually helped is this case?

So you can scroll to the reply by Investor in this link - Follow all the instructions and you would be ahead. It worked for me and my app works fine now.

@KoneeVibes
Copy link

Error: failed to fetch list: https://gateway.ipfs.io/ipns/tokens.uniswap.org
How can I fix it? ☹️
My part of package.json:

{
  "dependencies": {
    "@headlessui/react": "^1.7.19",
    "@headlessui/tailwindcss": "^0.2.0",
    "@uniswap/sdk-core": "^4.2.1",
    "@uniswap/v2-sdk": "^4.3.0",
    "@uniswap/v3-sdk": "^3.11.0",
    "@uniswap/widgets": "^2.59.0",
    "@web3-react/core": "^8.2.3",
    "next": "14.2.2",
    "react": "^18",
    "react-dom": "^18",
    "react-redux": "^8.1.3"
  },
  "devDependencies": {
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "eslint": "^8",
    "eslint-config-next": "14.2.2",
    "postcss": "^8",
    "tailwindcss": "^3.4.1",
    "typescript": "^5"
  }
}

when you open https://gateway.ipfs.io/ipns/tokens.uniswap.org in the browser you will be redirected to https://ipfs.io/ipns/tokens.uniswap.org

for me the new url works

<SwapWidget tokenList={'https://ipfs.io/ipns/tokens.uniswap.org'} />

Thanks for sharing this. I couldn't have thought of this solution. Now my widget works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests