Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error with cross-fetch in postgres-js & supabase-js #845

Open
2 tasks done
kokecar11 opened this issue Aug 25, 2023 · 13 comments
Open
2 tasks done

Error with cross-fetch in postgres-js & supabase-js #845

kokecar11 opened this issue Aug 25, 2023 · 13 comments
Labels
bug Something isn't working

Comments

@kokecar11
Copy link

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

I just upgraded to the latest Supabase-js package 2.33.1 when I try to use the api,

Uncaught (in promise) SyntaxError: The requested module '/node_modules/.pnpm/cross-fetch@3.1.8/node_modules/cross-fetch/dist/browser-ponyfill.js?v=bd2992b8' does not provide an export named 'default' (at PostgrestBuilder.ts:1:8)

I uninstalled node_modules and tried to reinstall them and I still get the error, all when running supabase-js

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

Captura de pantalla 2023-08-25 a la(s) 6 41 30 p m

System information

System:
OS: macOS 13.5
CPU: (8) arm64 Apple M1 Pro
Memory: 185.33 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.14.2 - ~/.nvm/versions/node/v18.14.2/bin/node
npm: 9.5.0 - ~/.nvm/versions/node/v18.14.2/bin/npm
Browsers:
Brave Browser: 116.1.57.47
Chrome: 116.0.5845.110
Safari: 16.6
npmPackages:
@builder.io/qwik: ^1.2.8 => 1.2.8
@builder.io/qwik-city: ^1.2.8 => 1.2.8
@supabase/supabase-js: ^2.33.1 => 2.33.1
undici: 5.22.1 => 5.22.1
vite: 4.3.5 => 4.3.5

Additional context

Add any other context about the problem here.

@kokecar11 kokecar11 added the bug Something isn't working label Aug 25, 2023
@kokecar11
Copy link
Author

With nextjs same issue please review and correct possible import errors
Captura de pantalla 2023-08-28 a la(s) 12 42 38 p m

@soedirgo
Copy link
Member

Seems like an issue on cross-fetch: lquixada/cross-fetch#120 (comment)

Can you run npm up @supabase/postgrest-js and see if the error changes? We're about to replace cross-fetch with using node-fetch directly which can possibly fix this.

@soedirgo
Copy link
Member

Also, can you share more of the logs from the Next.js/pnpm build?

@hash-bang
Copy link

@soedirgo - I'm also seeing this runtime error with the Vite framework.

What logs do you require exactly? Just a package-lock or something more specific?

@hash-bang
Copy link

To elaborate - I've got @supabase/supabase-js in a submodule that the main project is importing.
This submodule works fine when linked instead of installed which may suggest the issue is one of the pre-deps for @supabase/supabase-js not importing the updated version of node-fetch?

@hash-bang
Copy link

Alright after some hair pulling I got this to play nice with Vite.

It looks like some of the modules need explicit aliasing otherwise Vite / ESBuild / Rollup seems to get confused and import the wrong file.

Merge this into vite.config.js:

import { defineConfig } from 'vite';
export default defineConfig(({mode}) => ({
	// ... presumably other existing config ... //
	resolve: {
		alias: {
			'cross-fetch': 'cross-fetch/dist/browser-ponyfill.js',
			'@supabase/node-fetch': '@supabase/node-fetch/lib/index.mjs',
			'websocket': 'websocket/index.js'
		},
	},
}));

@soedirgo
Copy link
Member

soedirgo commented Sep 7, 2023

@hash-bang I'm referring to the Import trace for requested module logs above - the actual error messages should be above it.

Do you have a repo where I could reproduce this issue? I'd like to make this work OOtB if possible.

@hash-bang
Copy link

@soedirgo after playing around a bit it looks like this only seems to be a problem when Supabase is a sub-dependency (i.e. project imports NPM which then imports Supabase).

I've set up a simple demo of us using Supabase here its using our in house wrapping NPM Vitel which gives us a thin wrapper around Supabase to handle some company specific things.

@soedirgo
Copy link
Member

I don't see any relevant warnings in that demo. Am I missing a step?

Screenshot 2023-09-11 at 5 54 24 PM

In any case, does upgrading to supabase-js v2.33.2 help?

@hash-bang
Copy link

hash-bang commented Sep 12, 2023

I assume you're doing the "Open in new Tab" thing then opening the console there?

If so that's, odd because its the first error that shows up for me:

2023-09-12_11-21

One question though - if I'm right in assuming that node-fetch is the backend wrapper to ponyfill the fetch() API, is there a reason its not just falling back to using the native version for frontend imports if its already present?

Edit: I can also confirm that upping the sub-module to v2.33.2 has the same result - I've updated the demo link to reflect the new package-lock with that version.

@mikestopcontinues
Copy link

I'm having this problem too, with a Vite build. When we were still on cross-fetch, the alias hack worked for me. But it no longer does with @supabase/node-fetch.

@silentworks
Copy link

@mikestopcontinues please provide a GitHub repo with the reproduction of this issue. I tested the one @hash-bang provided above and cannot replicate the issue he is having either. It's also harder to download files off Stackblitz to run them locally to dig into the issue further.

@hash-bang
Copy link

@silentworks - apologies, I didn't know you had issues downloading the project.

Steps to reproduce:

  1. Download the Stackblitz export
  2. Run npm run dev
  3. Navigate to page with the devtools console open to see the above error with node-fetch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants