4

I am trying to fetch data from asp.net core api to svelte page. I got a self signed certificate error:

TypeError: fetch failed
    at node:internal/deps/undici/undici:12500:13
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  [cause]: Error: self-signed certificate
      at TLSSocket.onConnectSecure (node:_tls_wrap:1674:34)
      at TLSSocket.emit (node:events:520:28)
      at TLSSocket._finishInit (node:_tls_wrap:1085:8)
      at ssl.onhandshakedone (node:_tls_wrap:871:12)
      at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17) {
    code: 'DEPTH_ZERO_SELF_SIGNED_CERT'
  }
}

Next I used mkcert to create a certificate and key inside the project directory and then I updated vite.config.ts to look like this:

import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vite';
import fs from 'fs';

export default defineConfig({

    plugins: [sveltekit()],
    server: {
        https: {
            key: fs.readFileSync(`${__dirname}/cert/key.pem`),
            cert: fs.readFileSync(`${__dirname}/cert/cert.pem`)
        }
    }
});

Finally, when I start the sveltekit server I am greeted with this error in the browser:

TypeError: Could not convert argument of type symbol to string.
    at webidl.converters.DOMString (node:internal/deps/undici/undici:1940:15)
    at webidl.converters.ByteString (node:internal/deps/undici/undici:1945:35)
    at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1857:30)
    at webidl.converters.HeadersInit (node:internal/deps/undici/undici:3397:67)
    at Object.RequestInit (node:internal/deps/undici/undici:1914:21)
    at new Request (node:internal/deps/undici/undici:4821:34)
    at getRequest (file:///C:/path/to/project/Client/node_modules/@sveltejs/kit/src/exports/node/index.js:107:9)
    at file:///path/to/project/Client/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:497:2

BTW mkcert -install informed me that firefox is not supported on my platform.

Setting up the certificate for dev environment seems like a simple task, but I've been frustrated that I can't actually develop the website for quite some time now.

I want to fetch data from asp.net core api to a sveltekit front end, but I can't, because I get errors from which I can't make any sense.

1 Answer 1

11

Ran into this issue myself just now. I found that adding proxy: {} to the server object fixed it somehow.

export default defineConfig({
    plugins: ...,
    server: {
        https: {
            key: ...,
            cert: ...
        },
        // this line fixes it *somehow*
        proxy: {},
    }
});
1
  • Since writing this question I've decided to not use Svelte or any other frontend framework and just stick to ASP.NET Core's MVC. I can't check if this would work for me, so I'll just mark your answer as accepted. Commented May 28 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.