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

Crashing when calling fetch #5327

Closed
LeGmask opened this issue Jun 30, 2022 · 8 comments
Closed

Crashing when calling fetch #5327

LeGmask opened this issue Jun 30, 2022 · 8 comments

Comments

@LeGmask
Copy link

LeGmask commented Jun 30, 2022

Describe the bug

image
And the code :

<script lang="ts" context="module">
    import {route} from "../../Backend/api";
    import {customers} from "../../lib/store";

    export async function load({fetch}) {
        const response = await fetch(route('/customers'));

        customers.set(response.ok && (await response.json()));

        return {
            status: response.status,
        }
    }
</script>

<slot/>

Reproduction

Juste use fetch inside a load function.

Logs

terminated
TypeError: terminated
    at Fetch.onAborted (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:10624:49)
    at Fetch.emit (node:events:527:28)
    at Fetch.terminate (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:8903:10)
    at Object.onError (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:10758:34)
    at Request$4.onError (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:2209:27)
    at errorRequest (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:4759:13)
    at Socket.onSocketClose (file:///home/evann/Documents/sucre/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@sveltejs/kit/dist/node/polyfills.js:4033:5)
    at Socket.emit (node:events:527:28)
    at TCP.<anonymous> (node:net:740:14)

System Info

System:
    OS: Linux 5.18 Arch Linux
    CPU: (4) x64 Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
    Memory: 1006.43 MB / 7.64 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.3.0 - /usr/bin/node
    Yarn: 1.22.19 - /usr/bin/yarn
    npm: 8.5.5 - /usr/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.53 
    @sveltejs/kit: next => 1.0.0-next.357 
    svelte: ^3.48.0 => 3.48.0 

Severity

blocking an upgrade

Additional Information

It was working with
image

@Rich-Harris
Copy link
Member

"Juste use fetch inside a load function" is not a reproduction. Feel free to open a new issue when you have one.

@nickolasgregory
Copy link

nickolasgregory commented Jul 2, 2022

I too have encountered this error and it is certainly due to a fetch call running inside my load function.

  • Windows 11
  • Node v16.13.1
  • "@sveltejs/kit": {"version": "1.0.0-next.357" ... "@sveltejs/vite-plugin-svelte": "^1.0.0-next.48",

I'm also seeing this node warning

(node:9336) ExperimentalWarning: stream/web is an experimental feature. This feature could change at any time

Am investigating if it's platform related in some way as it doesn't seem to be a widely encountered error.

@anderfernandes
Copy link

anderfernandes commented Jul 2, 2022

I am seeing the same problem in Arch Linux and the latest MacOS. It looks like this has something todo with the fetch node polyfill defined in kit when the transition from node-fetch to undici was made. This is most likely a problem with undici as someone raised an issue with them about this error.

@anderfernandes
Copy link

Sorry for posting once again on a closed thread but, if anyone sees this, it's not a problem with Svelte Kit or undici, at least in my case.

Turns out this was a problem with the PHP CLI version 8.1.7-2 (in Arch Linux, not sure if it's limited to this OS/version). The backend is a Laravel app and I was running it with artisan (php -S would cause my fetch calls have the same problem). Once I ran Laravel with nginx and php-fpm there were no issues.

@guilledll
Copy link

guilledll commented Jul 19, 2022

Same error here, running php 8.1.8.
First a thougth it was a fetch() error but after trying serveal times and even using an external api, I was able to get a proper response of await response.json() without getting the terminated error.
I'm using Ubuntu 22.04 with apache 2 as php server.

As @anderfernandes suggested i installed nginx with php-fpm but the issue is still there, can you please provide more info about your solution, maybe how you installed and configured nginx? Tnanks in advance!

@anderfernandes
Copy link

Same error here, running php 8.1.8. First a thougth it was a fetch() error but after trying serveal times and even using an external api, I was able to get a proper response of await response.json() without getting the terminated error. I'm using Ubuntu 22.04 with apache 2 as php server.

As @anderfernandes suggested i installed nginx with php-fpm but the issue is still there, can you please provide more info about your solution, maybe how you installed and configured nginx? Tnanks in advance!

I used the same one as described here: https://laravel.com/docs/9.x/deployment#nginx.
Try doing your requests from a fresh SvelteKit install and see what happens.

@GCBenlloch
Copy link

I'm also getting TypeError: terminated when calling response.json(). The api is build with Laravel 9 and its working properly if called from postman.

TypeError: terminated
    at Fetch.onAborted (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:11998:50)
    at Fetch.emit (node:events:520:28)
    at Fetch.terminate (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:10257:11)
    at Object.onError (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:12132:35)
    at Request$3.onError (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:3163:27)
    at errorRequest (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:5746:13)
    at Socket.onSocketClose (file:///****/node_modules/@sveltejs/kit/dist/node/polyfills.js:5020:5)
    at Socket.emit (node:events:520:28)
    at TCP.<anonymous> (node:net:687:12)

My api is returning this headers:

Host: api.excursiones.local:8000
Date: Fri, 22 Jul 2022 09:22:31 GMT
Connection: close
X-Powered-By: PHP/7.3.27
Cache-Control: no-cache, private
Date: Fri, 22 Jul 2022 09:22:31 GMT
Content-Type: application/json
Vary: Origin

The response status after fetch is 200 and the response body is properly formated.

@anderfernandes
Copy link

I'm also getting TypeError: terminated when calling response.json(). The api is build with Laravel 9 and its working properly if called from postman.

TypeError: terminated
    at Fetch.onAborted (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:11998:50)
    at Fetch.emit (node:events:520:28)
    at Fetch.terminate (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:10257:11)
    at Object.onError (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:12132:35)
    at Request$3.onError (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:3163:27)
    at errorRequest (file:///C:/****/node_modules/@sveltejs/kit/dist/node/polyfills.js:5746:13)
    at Socket.onSocketClose (file:///****/node_modules/@sveltejs/kit/dist/node/polyfills.js:5020:5)
    at Socket.emit (node:events:520:28)
    at TCP.<anonymous> (node:net:687:12)

My api is returning this headers:

Host: api.excursiones.local:8000
Date: Fri, 22 Jul 2022 09:22:31 GMT
Connection: close
X-Powered-By: PHP/7.3.27
Cache-Control: no-cache, private
Date: Fri, 22 Jul 2022 09:22:31 GMT
Content-Type: application/json
Vary: Origin

The response status after fetch is 200 and the response body is properly formated.

According to their docs, Laravel is only supported in PHP 8.x.
https://laravel.com/docs/9.x/releases#support-policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants