ReferenceError: globalThis is not defined

Hey guys,

I am working on the ionic project and I am facing one issue. my app is working fine if I run it in the browser. but when I tried to run in the android it gives me an error

ReferenceError: globalThis is not defined
    at Module.<anonymous> (vendor-es5.js:158248)
    at Module.spgP (vendor-es5.js:158400)
    at __webpack_require__ (runtime-es5.js:85)
    at Module.ZAI4 (main-es5.js:295)
    at __webpack_require__ (runtime-es5.js:85)
    at Module.zUnb (main-es5.js:647)
    at __webpack_require__ (runtime-es5.js:85)
    at Object._ (main-es5.js:19)
    at __webpack_require__ (runtime-es5.js:85)
    at checkDeferredModules (runtime-es5.js:46)
capacitor.handleError @ capacitor-runtime.js:358
capacitor.handleWindowError @ capacitor-runtime.js:378 

I solved this issue by adding the globalthis package to the project.

use the following command to add globalthis to your project

npm install globalthis

after adding the package to the project import it in

src/plyfills.ts

 

import 'globalthis/auto'

 

Add comment