← All articles

Making an Ionic/Angular App Compatible with iOS 12 (Backward Compatibility)

Fix ReferenceError: Can't find variable: globalThis on iOS 12 by adding the @ungap/global-this polyfill to polyfills.ts.

Published
Making an Ionic/Angular App Compatible with iOS 12 (Backward Compatibility) cover image

I ran into a bit of trouble, so this is a memo. I am writing it down for anyone who hits the same issue. I think it is an Ionic/Angular problem, but it might be another library—I have not narrowed it down.

@angular/core@11.0.2
@ionic/angular@5.4.1


The latest iOS was fine, but I got a report that the site would not load on iOS 12. When I checked, I saw this error:

ReferenceError: Can't find variable: globalThis

It had worked before, so I think a recent version upgrade caused it. Since it says globalThis is missing, I fixed it by adding it to polyfills.ts.

First, install @ungap/global-this in the terminal.

npm i @ungap/global-this

Then import it in src/polyfills.ts.

/***************************************************************************************************
 * APPLICATION IMPORTS
 */
import '@ungap/global-this';

Simple, right? I learned something new this time: more users than I expected have not updated their iOS version, so you need to watch out. Because they can only update on Wi‑Fi, users without Wi‑Fi at home seem to miss updates.

See you next time.