[PR #8697] fix(sso): use namespace import for samlify to fix ESM compatibility #16400

Closed
opened 2026-04-13 10:30:45 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8697

State: closed
Merged: Yes


Summary

  • Fix TypeError: Cannot read properties of undefined (reading 'setSchemaValidator') during SAML initialization in ESM runtimes
  • samlify is a CJS module with __esModule: true but no exports.default. Using import saml from "samlify" resolves to undefined in ESM, causing saml.setSchemaValidator(...) to throw at module load time
  • Switch all three source files (index.ts, routes/sso.ts, routes/helpers.ts) from import saml from "samlify" to import * as saml from "samlify"
  • Update the smoke test to use native ESM import (import { sso } from "@better-auth/sso") instead of createRequire, and add a dedicated regression test for ESM module loading

Test plan

  • All 96 SAML unit tests pass (vitest packages/sso/src/saml.test.ts)
  • All 3 SAML smoke tests pass (node --test e2e/smoke/test/saml.spec.ts)
  • pnpm typecheck passes
  • pnpm lint passes
**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8697 **State:** closed **Merged:** Yes --- ## Summary - Fix `TypeError: Cannot read properties of undefined (reading 'setSchemaValidator')` during SAML initialization in ESM runtimes - `samlify` is a CJS module with `__esModule: true` but no `exports.default`. Using `import saml from "samlify"` resolves to `undefined` in ESM, causing `saml.setSchemaValidator(...)` to throw at module load time - Switch all three source files (`index.ts`, `routes/sso.ts`, `routes/helpers.ts`) from `import saml from "samlify"` to `import * as saml from "samlify"` - Update the smoke test to use native ESM import (`import { sso } from "@better-auth/sso"`) instead of `createRequire`, and add a dedicated regression test for ESM module loading ## Test plan - [x] All 96 SAML unit tests pass (`vitest packages/sso/src/saml.test.ts`) - [x] All 3 SAML smoke tests pass (`node --test e2e/smoke/test/saml.spec.ts`) - [x] `pnpm typecheck` passes - [x] `pnpm lint` passes
GiteaMirror added the pull-request label 2026-04-13 10:30:45 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#16400