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: global is not defined in runtime

See original GitHub issue

Describe the bug Error when executing the example code

SDK Version (if relevant)@walletconnect/sign-client”: “2.1.3”, “typescript”: “^4.9.3”, “vite”: “^3.2.4”

To Reproduce Checkout branch global-is-not-defined of repo: https://github.com/smelnikov/walletconnect-sample

yarn install
npx vite

A runtime error appears:

Uncaught ReferenceError: global is not defined
    at localStorage.js:49:3
    at node_modules/localStorage/lib/localStorage.js (localStorage.js:54:1)
    at __require2 (@walletconnect_sign-client.js?v=a6844a88:18:50)
    at node_modules/@walletconnect/keyvaluestorage/dist/cjs/browser/index.js (index.ts:1:1)
    at __require2 (@walletconnect_sign-client.js?v=a6844a88:18:50)
    at index.js:1848:18

Expected behavior There are no errors in runtime.

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
smelnikovcommented, Nov 21, 2022

@bkrem I solved this problem with define global variable during build https://github.com/smelnikov/walletconnect-sample/commit/a4e658ee2b6cfaa6b5de5447dacc54eff342267f

But it looks like this must be fixed at the top level of the library.

1reaction
bkremcommented, Nov 21, 2022

Thanks for raising this and especially including a repro for it @smelnikov 💯

While https://github.com/WalletConnect/walletconnect-utils/pull/36 will fix this type of issue for the code we (WalletConnect) own, this seems to be a reference in the localStorage dependency.

Did some digging and found the global reference here: https://git.coolaj86.com/coolaj86/local-storage.js/src/branch/local-storage/lib/localStorage.js#L49

cc @ganchoradkov, not sure what the best move here is, but I suspect we either:

  • Submit a patch to the localStorage lib (who knows if/when that gets merged)
  • Fork it and patch ourselves so we own the code.
  • Use a different localStorage lib (seems drastic for an env/global reference issue but maybe wise long term)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: global is not defined #2141 - GitHub
ncaught ReferenceError: global is not defined at Object../node_modules/buffer/index.js (index.js:43) at webpack_require (bootstrap:76)
Read more >
Upgrading to angular-6.x gives "Uncaught ReferenceError
Then you're getting the following error Fix: "Uncaught ReferenceError: global is not defined" do it as follows node: { global: true, ...
Read more >
How to fix the ReferenceError: global is not defined error in ...
That sound simple enough to fix, just create a vite.config.[js/ts] file, add it to your SvelteKit project and define global right? // vite....
Read more >
global is not defined react - You.com | The AI Search Engine ...
I did not need to install babel-runtime as other answers are suggesting. Open side panel. Uncaught ReferenceError: global is not defined at eval....
Read more >
Error "global is not defined" with agent-js - DFINITY Forums
I get following error at runtime: Uncaught (in promise) ReferenceError: global is not defined The errors occurs there (minimized code and ...
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