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

Isomorphism breaks due to Websockets when using SSR #155

Closed
ixxie opened this issue Apr 14, 2021 · 9 comments
Closed

Isomorphism breaks due to Websockets when using SSR #155

ixxie opened this issue Apr 14, 2021 · 9 comments
Labels
bug Something isn't working released

Comments

@ixxie
Copy link

ixxie commented Apr 14, 2021

Bug report

Describe the bug

When importing createClient into a SvelteKit project, the following error is raised:

5:49:56 PM [vite] Error when evaluating SSR module /node_modules/websocket/lib/browser.js?v=f34fcf64:
Error: Could not determine global this
    at /node_modules/websocket/lib/browser.js?v=f34fcf64:7:28
    at instantiateModule (/home/ixxie/repos/minex/node_modules/vite/dist/node/chunks/dep-66eb515d.js:69030:166)

It seems to come from this block of code in the Websockets package.

To Reproduce

npm init svelte@next
npm install
npm install --save-prod @supabase/supabase-js
sed -i "s/<script>/<script>\n\timport { createClient } from '@supabase\/supabase-js';/" ./src/routes/index.svelte
npm run dev

Expected behavior

Import should work without error

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • Version of supabase-js: 1.11.2
  • Version of Node.js: 14.15.4

Additional context

This was discovered after resolving #153, after which @kiwicopple recommended I create a new issue.

@ixxie
Copy link
Author

ixxie commented Apr 14, 2021

I've now tried a similar minimal example using es5-ext/global directly and it seems the root of the issue is there. It seems this package is abandoned (not github activity for a year) and perhaps an alternative should be suggested to the websocket maintainers but I am not sure what it would be...

@ixxie ixxie changed the title Isomorphy breaks due to Websockets when using SSR Isomorphism breaks due to Websockets when using SSR Apr 14, 2021
@benmccann
Copy link

@ixxie
Copy link
Author

ixxie commented Apr 14, 2021

@benmccann this is what I suggested and this was already released into websockets@1.0.34 by its maintainer (see theturtle32/WebSocket-Node#415).

@kiwicopple
Copy link
Member

We originally used globalThis in gotrue and had to polyfill it: supabase/auth-js#38

I find this a bit odd though, because our supabase-js client is isomorphic. We already use it in a node environment and it works fine 🤔

@benmccann
Copy link

Anyway, this issue seems fixed by websocket@1.0.34, so at most we'd need to upgrade package.json and then can close this

@benmccann
Copy link

I'm not sure if it's related to the globalThis issue, but once the globalThis issue is fixed I encounter another issue that seems to be a Vite bug: vitejs/vite#2995

@kiwicopple
Copy link
Member

OK I bumped to the latest. I'll leave this open if anyone can confirm the fix?

@kiwicopple kiwicopple reopened this Apr 15, 2021
@kiwicopple
Copy link
Member

🎉 This issue has been resolved in version 1.11.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

@benmccann
Copy link

Thanks! There's multiple issues left running Supabase with SvelteKit, but they're pretty clearly issues with Vite so we'll work on those in that repo. Thanks for all your help!

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

No branches or pull requests

3 participants