"Data layer compatibility mode" problem Zaraz

Our domain runs a Next website, a React SPA, and KeyCloak for Authentication.
Zaraz consent is enabled for our domain.

With Data layer compatibility mode enabled, I get the following error in the console:

Uncaught TypeError: w.zaraz is undefined
    _rl s.js:5
    replaceState s.js:5
    wt keycloak.mjs:250

The error references Zaraz related code: const dt = w.dataLayer.push;.

With Data layer compatibility mode disabled, I get the a different error in the console but only for KeyCloak. But it’s a bigger problem than the previous error, since KeyCloak indefinitely tries to keep loading:

Uncaught TypeError: w.zaraz is undefined
    _rl s.js:5
    replaceState s.js:5
    wt keycloak.mjs:250

What to do? How can I make Zaraz consent work on our domain?

2 posts were merged into an existing topic: Uncaught TypeError error in console coming from Zaraz