简体   繁体   中英

Sveltekit error: self signed certificate in certificate chain

I have a strange thing going on. I'm using sveltekit for the first time and in my project I was going to call an api to fetch data and got error: request to ' ' failed, reason: self signed certificate in certificate chain. And this was in the sveltekit loading function. When I did the same thing in onMount in a component it works like a charm.

So I decided to start a new project from scratch using the sveltekit demo template. And without changing anything going to the todo page and getting the same thing:

request to https://api.svelte.dev/todos/98e351d failed, reason: self signed certificate in certificate chain FetchError: request to https://api.svelte.dev/todos/98e351d failed, reason: self signed certificate in certificate chain at ClientRequest. (file:///C:/Users/myuser/Desktop/my-app/node_modules/@sveltejs/kit/dist/install-fetch.js:6246:11) at ClientRequest.emit (node:events:390:28) at TLSSocket.socketErrorListener (node:_http_client:447:9) at TLSSocket.emit (node:events:390:28) at emitErrorNT (node:internal/streams/destroy:157:8) at emitErrorCloseNT (node:internal/streams/destroy:122:3) at processTicksAndRejections (node:internal/process/task_queues:83:21)

And shouldn't the demo template work without any certificate? So decided to start a demo template on another computer. And there the todo page works as it should. Without any error. I have looked around for someone with a similar problem and there is a lot of people getting self signed certificate error but not related to sveltekit or similar to my problem.

Any idea? Thanks.

Because SvelteKit uses SSR , when you fetch a URL from outside onMount , SvelteKit processes it on the server side (ie through node.js). But when you fetch a URL from onMount it is processed on the client side (ie through browser).

I think your self-signed certificate is installed in browser but doesn't installed in node.js. This is the reason why the error is occurred when you fetch the URL from outside onMount and not occurred when you fetch it from inside onMount .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM