Bug:jsDelivr +esm breaks Supabase JS v2 due to default imports of modules exporting default null
#41118
Unanswered
troop194roselle-art
asked this question in
Questions
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
Using Supabase JS v2 directly in a browser via jsDelivr
+esmcan fail at runtime with errors such as:Uncaught TypeError: Cannot read properties of null (reading 'AuthClient')
Uncaught TypeError: Cannot read properties of null (reading 'FunctionsHttpError')
Environment
<script type="module">)import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm';
Root Cause
Several Supabase submodules (e.g. @supabase/auth-js, @supabase/functions-js) explicitly define:
export default null;
and expose their APIs exclusively via named exports (e.g. AuthClient, FunctionsHttpError).
The jsDelivr +esm rewrite imports these modules using default imports:
import s from 'https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm';
Because the default export is explicitly null, the imported value is null, causing runtime failures when Supabase JS accesses:
s.AuthClient
s.FunctionsHttpError
This affects multiple submodules.
Minimal Reproduction
<script type="module"> import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2/+esm';The script loads, then fails at runtime when auth or functions code is evaluated.
Why this matters
unpkg.com cannot be used as a fallback because it does not rewrite bare imports
jsDelivr +esm is the only documented way to use Supabase JS without a bundler
This results in runtime failures without user misconfiguration
How I worked around this locally
To isolate the issue, I copied the jsDelivr-generated ESM output of
@supabase/supabase-jslocally and modified its imports.Specifically:
I modified
import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm';
to
import {createClient } from './localClient.js';
Original (jsDelivr output) was copied to localClient.js.
@supabase/auth-js:Original (jsDelivr output):
import s from "https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm";
then modified locally to:
import * as s from "https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm";
What is required to resolve this issue
The jsDelivr
+esmoutput must not import Supabase submodules using default imports when those modules explicitly defineexport default null.Specifically, imports such as:
import s from "https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm";
must be replaced with namespace or named imports, for example:
import * as s from "https://cdn.jsdelivr.net/npm/@supabase/auth-js@2/+esm";
Beta Was this translation helpful? Give feedback.
All reactions