question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: Can't find variable: global

See original GitHub issue

My build vite vue3 and packages vue-router and pinia. I have tried a lot variants and even the simplest one throws the same error every time. When I try to initialize WallectConnectProvider like that:

import WalletconnectProvider from '@walletconnect/web3-provider'

async function connect() {
  const config = {97: 'https://data-seed-prebsc-1-s1.binance.org:8545/'}
  const wc = new WalletconnectProvider({rpc: config})
  // await wc.enable()
}

Page immediately crushes with error: ReferenceError: Can't find variable: global.

Seems like this problem appeared on vue3 + vite. I researched a lot and found that the problem possible on walletconnect lib side

Repo for recreation of problem: vue-wc-problem

Node version 16.13.2

npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers

  System:
    OS: macOS 11.6.2
    CPU: (4) x64 Intel(R) Core(TM) i5-4250U CPU @ 1.30GHz
    Memory: 178.09 MB / 4.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.13.2 - ~/.nvm/versions/node/v16.13.2/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Safari: 15.2
  npmPackages:
    @vitejs/plugin-vue: ^2.0.1 => 2.1.0 
    vite: ^2.7.13 => 2.7.13

I have tried in dev and build modes same problem

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:3
  • Comments:11

github_iconTop GitHub Comments

6reactions
frangtecommented, May 18, 2022
import WalletConnectProvider from '@walletconnect/web3-provider/dist/umd/index.min.js'
import QRCodeModal from '@walletconnect/qrcode-modal/dist/umd/index.min.js'

try this

3reactions
FounderCaseycommented, Aug 2, 2022

As @armgit5 mentioned, this currently works: https://stackoverflow.com/questions/70714690/buffer-is-not-defined-in-react-vite

npm i @esbuild-plugins/node-globals-polyfill

Inside your vite.config.js file:

Import the package:

import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'

And then add optimizeDeps to the config:

export default defineConfig({
    // ...other config settings
    optimizeDeps: {
        esbuildOptions: {
            // Node.js global to browser globalThis
            define: {
                global: 'globalThis'
            },
            // Enable esbuild polyfill plugins
            plugins: [
                NodeGlobalsPolyfillPlugin({
                    buffer: true
                })
            ]
        }
    }
})

Currently working as of 8/2/22 - Vite(2.9.12) / Vue 3(3.2.37)

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: Can't find variable: global #10824 - GitHub
A workaround fixed the issue: Workaround 1: add (windows as any).global = window to polyfills.ts; Workaround 2: add window.global = window to ...
Read more >
ReferenceError: Can't find variable: globalThis - Stack Overflow
I have a angular 9 based website which is hosted in firebase. I have an issue which happens only on some devices like...
Read more >
It keeps saying "Reference error: can't find variable"
It keeps saying "Reference error: can't find variable". This is my code: var userChoice = function(question) { question = prompt(“Do you choose rock,...
Read more >
ReferenceError: "x" is not defined - JavaScript - MDN Web Docs
ReferenceError : "x" is not defined. The JavaScript exception "variable is not defined" occurs when there is a non-existent variable referenced somewhere.
Read more >
Can't find variable: __scanCodes in React Native Vision Camera
ReferenceError : Can't find variable : __scanCodesPlease do like share and comment if you like the video please do hit like and if...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found