supabase: Supabase fails to load in web component
Bug report
- I confirm this is a bug with Supabase, not with my own application.
- I confirm I have searched the Docs, GitHub Discussions, and Discord.
Describe the bug
Adding a component that uses Supabase to Shoelace components produces the following error:
SyntaxError: The requested module './../../../node-fetch/lib/index.js' does not provide an export named 'default' (at PostgrestBuilder.js:1:8)
Which references this line in PostgrestBuild.js:
// @ts-ignore
import nodeFetch from '@supabase/node-fetch';
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
git clone https://github.com/shoelace-style/shoelacecd shoelacenpm install @supabase/supabase-jsnpm installnpm run buildnpm run test=> All tests pass, check.- Add Supabase to one of the components such as
src/components/alert/alert.component.tsby adding the following two lines after the existingimportstatements:
import { createClient } from '@supabase/supabase-js'
createClient('https://xyzcompany.supabase.co', 'public-anon-key')
npm run test- Observe that now all tests fail to even load, each giving an error of the following form:
src/components/alert/alert.test.ts:
đźš§ Browser logs on Chromium:
SyntaxError: The requested module './../../../node-fetch/lib/index.js' does not provide an export named 'default'
đźš§ Browser logs on Webkit:
SyntaxError: Importing binding name 'default' cannot be resolved by star export entries.
❌ Could not import your test module. Check the browser logs or open the browser in debug mode for more information.
Expected behavior
Adding Supabase to a component should not cause its test and the tests of all other components in the package to fail to load.
System information
- OS: macOS Sonoma 14.2.1
- Browsers tested: chrome, safari
- Version of supabase-js: 2.39.6
- Version of Node.js: 21.5.0
Related report
This open issue appears to be related, but since it did not include a detailed means to reproduce, I thought I’d create a new issue to facilitate reproduction in hopes to resolve this more quickly:
(I initially opened an issue at @supabase/postgrest-js repo, but this problem is more pervasive as it prevents any Supabase functions from working since supabase-js cannot even load.)
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 1
- Comments: 16 (6 by maintainers)
@encima: Thank you for re-opening.
I see you’ve removed
bugand addedneeds-analysis. Ok, let me try to jumpstart analysis:node-fetchshould not even be needed because browsers have nativefetchsupport.@supabase/*package has the followingpackage.jsonproperties:@supabase/node-fetch, which is noted in the error message as failing to import inPostgrestBuilder.js:1:8.The above suggests that Supabase is perhaps not robustly handling its
fetch()needs for ESM modules in the browser, either because it ought to be using the browser-nativefetch()rather thannode-fetchor because@supabase/node-fetchis not configured in the manner of all other@supabase/*packages wrt the above notedpackage.jsonproperties.This improper importing of supabase node-fetch inside supabase-postgrest is causing vitest not to run at all. We have confirmed that removing the supabase package fixes this issue. We have dozens of dependencies across multiple projects and only this one causes this issue.
@kjhughes I’m actually here to try and fix the issue. I’ll investigate a bit more and try to create reproduction steps and then a fix for it. Also note the Supabase team always tries to fix higher priority stuff first, I’m no longer a Supabase staff but I know how things work internally and know stuff like this isn’t ignored. They are just not as high of a priority as other tasks that user’s are requesting for, a case and point is I have never ran into this issue before and I have working playwright tests in my project and this hasn’t shown up.
@encima : If your argument is that my issue title is too broad in saying “web components”, you’ve proven your point. I am fine with narrowing the scope of the description per your suggestion.
However, the problem remains that I cannot call
createClient()becauseimport { createClient } from '@supabase/supabase-js'is failing in a context that uses well-established techniques. I’ve provided the exact steps to reproduce, and the only change to the working tests is the addition ofI should be able to call
createClient()in this manner. At least two others that I’ve found have reported receiving a similar error in another context. I thought it would help to provide specific, easily reproducible steps that might be used to identify the problem.