Skip to content

Fix: TypeError when CordovaAuth0Plugin is not a constructor (auth0-js 9.30.1+) #2742

Merged
ankita10119 merged 1 commit intomasterfrom
fix/cordova-auth0-plugin-constructor
Mar 18, 2026
Merged

Fix: TypeError when CordovaAuth0Plugin is not a constructor (auth0-js 9.30.1+) #2742
ankita10119 merged 1 commit intomasterfrom
fix/cordova-auth0-plugin-constructor

Conversation

@ankita10119
Copy link
Contributor

@ankita10119 ankita10119 commented Mar 18, 2026

Changes

Problem

Users installing auth0-lock get the following error on Lock initialization, preventing the widget from rendering entirely:

Uncaught TypeError: CordovaAuth0Plugin is not a constructor at Auth0APIClient (p2_api.js)

This affects any fresh install of auth0-lock since auth0-js ^9.29.0 resolves to 9.30.1+ on npm.

Root Cause

auth0-js 9.30.0 introduced a Rollup build tooling change (via #1563) that changed how cordova-auth0-plugin.min.js bundles its exports. As a result, when webpack's ESM interop resolves the module, the default export is an empty object {} instead of the constructor function - breaking new CordovaAuth0Plugin() in p2_api.js

auth0-js version cordova-auth0-plugin.min.js export
<= 9.29.0 function (valid constructor) ✅
>= 9.30.1 {} (empty object) ❌

Fix

Guard the instantiation with a typeof check - if CordovaAuth0Plugin is not a valid constructor, fall back to an empty plugins array:

// Before
plugins: opts.plugins || [new CordovaAuth0Plugin()],

// After
plugins: opts.plugins || (typeof CordovaAuth0Plugin === 'function' ? [new CordovaAuth0Plugin()] : []),

This is safe because plugins is optional in auth0-js's WebAuth - the Cordova plugin only applies in Cordova environments. Web-based auth flows are unaffected.

References

SDK-8308

Testing

  • Reproduced the error by installing auth0-lock@14.2.4 with auth0-js@9.31.0 in a React app, Lock failed to initialize with the TypeError
  • Applied the fix via local build, Lock initializes correctly, widget renders, login flow works end to end
  • Confirmed auth0-js <= 9.29.0 (where the plugin exports a function) continues to work correctly since typeof function === 'function' is true
  • This change adds unit test coverage
  • This change adds integration test coverage
  • This change has been tested on the latest version of the platform/language

Checklist

@ankita10119 ankita10119 requested a review from a team as a code owner March 18, 2026 09:17
@ankita10119 ankita10119 merged commit bfa031b into master Mar 18, 2026
5 checks passed
@ankita10119 ankita10119 deleted the fix/cordova-auth0-plugin-constructor branch March 18, 2026 12:21
@ankita10119 ankita10119 mentioned this pull request Mar 19, 2026
ankita10119 added a commit that referenced this pull request Mar 19, 2026
**Fixed**
- Fix: TypeError when CordovaAuth0Plugin is not a constructor (auth0-js
9.30.1+) [\#2742](#2742)
([ankita10119](https://github.com/ankita10119))
- Fix: TypeError in matchConnection for enterprise connections with no
domains [\#2736](#2736)
([ankita10119](https://github.com/ankita10119))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants