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

Unable to use Torus with SvelteKit svelte.config.js #523

Open
Adamj1232 opened this issue Dec 13, 2022 · 0 comments
Open

Unable to use Torus with SvelteKit svelte.config.js #523

Adamj1232 opened this issue Dec 13, 2022 · 0 comments

Comments

@Adamj1232
Copy link

All builds and works fine locally and in other build environments but within svelteKit, SSR with svelte.config.js as shown below Torus throws an error.
svelte.config.js:
Link to repo

import adapterStatic from '@sveltejs/adapter-static'
import adapterVercel from '@sveltejs/adapter-vercel'
import { kitDocsPlugin } from '@svelteness/kit-docs/node'
import Icons from 'unplugin-icons/vite'
import preprocess from 'svelte-preprocess'
import { resolve } from 'path'
import nodePolyfills from 'rollup-plugin-polyfill-node'
const MODE = process.env.NODE_ENV

const development = MODE === 'development'

const { adapter, adapterName } = process.env.VERCEL
  ? { adapter: adapterVercel, adapterName: 'vercel' }
  : { adapter: adapterStatic, adapterName: 'static' }

console.log(`Using ${adapterName} adapter`)

/** @type {import('@sveltejs/kit').Config} */
const config = {
  extensions: ['.svelte', '.md'],
  preprocess: [
    preprocess({
      postcss: true
    })
  ],

  kit: {
    adapter: adapter(),
    prerender: {
      default: true,
      entries: ['*']
    },
    vite: {
      build: {
        rollupOptions: {
          external: [
            '@web3-react/core',
            '@web3-react/eip1193',
            '@web3-react/metamask',
            '@web3-react/network',
            '@web3-react/walletconnect',
            '@web3-react/types',
            '@web3-react/url',
            '@web3-onboard/*'
          ],
          plugins: [nodePolyfills({ crypto: true, http: true })]
        },
        commonjsOptions: {
          transformMixedEsModules: true
        }
      },
      resolve: {
        alias: {
          $fonts: resolve(process.cwd(), 'src/lib/fonts'),
          crypto: 'crypto-browserify',
          stream: 'stream-browserify',
          assert: 'assert'
        }
      },
      plugins: [
        Icons({ compiler: 'svelte' }),
        kitDocsPlugin({
          shiki: {
            theme: 'material-ocean'
          }
        }),
        development &&
          nodePolyfills({
            include: ['node_modules/**/*.js', new RegExp('node_modules/.vite/.*js')],
            http: true,
            crypto: true
          })
      ],
      define: {
        'import.meta.env.VERCEL': JSON.stringify(process.env.VERCEL)
      },
      optimizeDeps: {
        exclude: ['@ethersproject/hash', 'wrtc', 'http'],
        include: [
          '@web3-onboard/core',
          '@web3-onboard/gas',
          '@web3-onboard/sequence',
          '@web3-onboard/torus',
          'js-sha3',
          '@ethersproject/bignumber'
        ]
      }
    }
  }
}

export default config

Error:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'call')
    at new C (index-efeef119.js:1:16193)
    at r.<anonymous> (openloginJrpc.esm-fb99c9a3.js:2:3263)
    at new r (openloginJrpc.esm-fb99c9a3.js:2:3787)
    at Ht._setupWeb3 (torus.esm-46dda450.js:14:9082)
    at torusIframe.onload

To Reproduce
Steps to reproduce the behavior:

  1. Go to Blocknative's Onboard Docs
  2. Click on Connect button in the upper right corner
  3. Select Torus
  4. See error in terminal

Expected behavior
Wallet connects as expected after deployment. Wallet works fine locally.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Mac
  • Browser All

Additional context
Works fine in Webpack, CRACO and ReactApp Rewired Build Env

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

1 participant