tmedwards / sugarcube-2

SugarCube is a free (gratis and libre) story format for Twine/Twee.
https://www.motoslave.net/sugarcube/2/
BSD 2-Clause "Simplified" License
177 stars 41 forks source link

ReqTypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body. #306

Closed sizhongbin closed 3 months ago

sizhongbin commented 3 months ago

Describe the bug. When I try to use supabase-js library to fetch data from my database in Supabase, I will get this error. I've tried the same code in a simple HTML file and it works well.

To Reproduce: Steps to reproduce the behavior:

  1. Put the following code in a file: <script type="module"> import('https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm').then(({ createClient }) => { const supabase = createClient('https://gsxwebojwtxgmtvohfdv.supabase.co', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImdzeHdlYm9qd3R4Z210dm9oZmR2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MTc2NDg2MzAsImV4cCI6MjAzMzIyNDYzMH0.1XhzomAchqFjRrjscXtXIV4KUmnStjxkOF0cV7NLRQY'); console.log('Supabase Instance: ', supabase); supabase.auth.signInWithPassword({ email: 'test@test', password: 'test1234' }).then(({ data, error }) => { console.log('SUCCEED. Response: ', data); supabase.from('character').select('character_id').then( ({ data, error }) => { console.log('Data: ', data); console.log('Error: ', error); }) }) }) </script>
  2. Add the code in the compiled HTML's head using tweego with --head.
  3. See the error in console.

Expected behavior. The code should works like how it is in simple HTML file. data should be an array and error should be null.

Screenshots. N/A

Project details.

Smartphone/tablet details.

Additional context. Add any other context about the problem here.

tmedwards commented 3 months ago

Why are you using such an old version of SugarCube and what is the error?

Also, you need to format that code. Use a code fence.

sizhongbin commented 3 months ago

Why are you using such an old version of SugarCube and what is the error?

Also, you need to format that code. Use a code fence.

Sorry I'm using 2.36.1. I've updated.

The error is in title. ReqTypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

sizhongbin commented 3 months ago

Actually I'm not sure if its a bug or not. And I'm not sure if its caused by sugarcube or by tweego. I've also tried to use the supabase REST API instead of supabase-js library and everything goes well. const url = `${setup.url}/rest/v1/character`; const headers = new Headers({ apikey: setup.anonKey, Authorization: `Bearer ${setup.access_token}` }); fetch(url, { method: 'GET', headers: headers }) .then(response => { if (!response.ok) { throw new Error('Network response was not ok'); } console.log(response); return response.json(); }) .then(data => { console.log('data: ', data); }) .catch(error => { console.error('error:', error); }); }; And some other functions like auth.signUp(), auth.signInWithPassword(), insert() in supabase-js also works well in tweego compiled HTML. Looks like the error only occurs when I try to use select(). That's quite strange.

sizhongbin commented 3 months ago

Confirmed that the error will not occur in v2.37.0 I will upgrade my sugarcube version. Thanks!