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.

globalThis is not defined

See original GitHub issue

“duplicate?”: Probably because of

Describe the bug

When I use globalThis I get the following error:


Did you try recovering your dependencies?

npm --version

Which terms did you search for in User Guide?

I searched globalThis. While typing it was on global and the autocomplete suggestions included this:

which provides a workaround: Use window instead. However i’d rather use globalThis anyways.


(paste the output of the command here.)

PS C:\Users\Steven\Documents\code\js\sudoku\solver> create-react-app --info    
Environment Info:

  current version of create-react-app: 4.0.3
  running from C:\Users\Steven\AppData\Roaming\npm\node_modules\create-react-app

    OS: Windows 10 10.0.19042
    CPU: (4) x64 Intel(R) Core(TM) i5-3470 CPU @ 3.20GHz  
    Node: 16.0.0 - C:\Program Files\nodejs\node.EXE       
    Yarn: Not Found
    npm: 7.11.2 - C:\Program Files\nodejs\npm.CMD
    Chrome: 90.0.4430.93
    Edge: Spartan (44.19041.906.0), Chromium (90.0.818.51)
    Internet Explorer: Not Found
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    react-scripts: 4.0.3 => 4.0.3
    create-react-app: Not Found

Steps to reproduce

(Write your steps here:)

  1. use globalThis

Expected behavior

(Write what you thought would happen.)

It would work

Actual behavior

(Write what happened. Please add screenshots!)

### Describe the bug

When I use `globalThis` I get the following error:


Reproducible demo

untested demo

// index.js

// <default code>

(Paste the link to an example project and exact instructions to reproduce the issue.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

icecream17commented, Aug 31, 2021
declare global {
   interface Window {
      myAwesomeGlobalVar: YourType

The best solution is to import your variables if you can…

icecream17commented, Oct 19, 2021

fixed with general dependency updates in create-react-app v5

Read more comments on GitHub >

github_iconTop Results From Across the Web

ReferenceError: globalThis is not defined - npm - Stack Overflow
Consider updating your version of node.js to >=12 . globalThis was added in node.js v12.0.0 according to this compatibility table.
Read more >
ReferenceError: globalThis is not defined · Issue #2795 - GitHub
ReferenceError : globalThis is not defined at evalmachine.<anonymous>:1:1 at Script.runInContext (vm.js:133:20) at Object.
Read more >
'globalThis' is not defined - Microsoft Community
I am not able to access any files on Microsoft Teams and any time I try to ''globalThis' is not defined" keeps coming...
Read more >
globalThis is not defined although node version is v14.4.0
If you experience errors saying that globalThis is not defined, be sure to run a recent version of Node.js (at least 12.0). node...
Read more >
'globalThis is not defined' in JSS Site - Rock, Paper, Sitecore
[NodeInvocationException: globalThis is not defined ReferenceError: globalThis is not defined at react.Component.react.Component.
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 Post

No results found

github_iconTop Related Hashnode Post

No results found