arrow_back Back to Notebook
typescript
typescript
December 10, 2020

How to fix ReferenceError: globalThis is not defined

"ReferenceError: globalThis is not defined" is an error produced by some newer JavaScript libraries as they access globalThis.

How to fix

To fix this error you need to be using a version of node12+ however this may not solve the error on some browsers.

Install the polyfill

I recommend adding a polyfill for globalThis to ensure that the error is fixed over every environment.

npm i globalthis

inside polyfill.js add the following line

import 'globalthis/polyfill';

or import it into your file using

var globalThis = require('globalthis/polyfill')();

Thanks for reading!

John Wiseman

Full-Stack Software Engineer building scalable digital solutions. specializing in modern web technologies and mission-critical systems.

© 2026 Wiseman Systems Pty. Ltd.

Navigation

Start a Conversation

Ready to discuss your next project? Let's build something extraordinary together.

Get in Touch