sveltejs / svelte

web development for the rest of us
https://svelte.dev
MIT License
79.6k stars 4.21k forks source link

Getting "TypeError: Could not convert argument of type symbol to string." with Node 20 #12398

Closed YusufFidan closed 3 months ago

YusufFidan commented 3 months ago

Describe the bug

I'm using svelte for a while. After Update to Node 20.15.1 I got following error:

TypeError: Could not convert argument of type symbol to string.
    at webidl.converters.DOMString (node:internal/deps/undici/undici:1977:15)
    at webidl.converters.ByteString (node:internal/deps/undici/undici:1982:35)
    at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1894:30)
    at webidl.converters.HeadersInit (node:internal/deps/undici/undici:3424:67)
    at Object.RequestInit (node:internal/deps/undici/undici:1951:21)
    at new Request (node:internal/deps/undici/undici:4835:34)
    at getRequest (file:///Users/yfidan/projects/kronos/node_modules/@sveltejs/kit/src/exports/node/index.js:107:9)
    at file:///Users/yfidan/projects/kronos/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:497:27

This is my svelte.config.js


import adapterNode from '@sveltejs/adapter-node';

import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'
import pkg from 'svelte-preprocess';
import fs from 'fs'
import path from 'path';
import { fileURLToPath } from 'url';

const sveltePreprocess = pkg;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

/** @type {import('@sveltejs/kit').Config} */
const config = {
    // Consult https://kit.svelte.dev/docs/integrations#preprocessors
    // for more information about preprocessors
    preprocess: [vitePreprocess(), sveltePreprocess()],
    kit: {
        adapter: adapterNode({
             out: 'build',
             precompress: false,
             envPrefix: '',
             polyfill: true
         }),
        alias: {
            '@components': path.resolve('./src/lib/components'),
            '@lib': path.resolve('./src/lib'),
            '@store': path.resolve('./src/lib/stores'),
        },
    },
    server: {
        https: {
            key: fs.readFileSync(path.resolve(__dirname,'server.key')),

            cert: fs.readFileSync(path.resolve(__dirname,'server.cert'))
        },
        proxy: {},
    }
};

export default config;

Reproduction

nvm use 20 (uses latest 20.15.1) I'm getting the described error. After some tests the Problem causes with node >= 20.12.0

The project seems running properly

$  nvm use 20
Now using node v20.15.1 (npm v10.7.0)
$ npm run dev

> kronos@0.0.1 dev
> vite dev --host kronos.ddev.site --port 8443

07:36:19 [vite-plugin-svelte] WARNING: The following packages have a svelte field in their package.json but no exports condition for svelte.

@tinymce/tinymce-svelte@1.0.1
svelecte@3.16.4
svelte-awesome@3.2.1
svelte-forms-lib@2.0.1
svelte-pdf@1.0.20
svelte-hero-icons@4.1.3
svelte-pdf-simple@2.0.0
svelte-select@1.3.0
svelte-yup@1.0.5
svelte-spa-router@3.3.0
simple-svelte-autocomplete@2.5.2
svelte-tiny-virtual-list@2.0.5

Please see https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#missing-exports-condition for details.

  VITE v5.0.12  ready in 538 ms

  -  Network: https://kronos.ddev.site:8443/
  -  press h + enter to show help

Logs

No response

System Info

System:
    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 2.03 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.15.1 - ~/.nvm/versions/node/v20.15.1/bin/node
    npm: 10.7.0 - ~/.nvm/versions/node/v20.15.1/bin/npm
  Browsers:
    Chrome: 126.0.6478.127
    Safari: 17.5
  npmPackages:
    svelte: ~4.2.9 => 4.2.9

Severity

annoyance

Conduitry commented 3 months ago

Please provide a minimal reproduction, and not just the contents of your svelte.config.js.

YusufFidan commented 3 months ago

But this is exactly what happened:

$  nvm use 20
Now using node v20.15.1 (npm v10.7.0)
$ npm run dev

After this the project seems to start properly, as in reproduction. The browser says this ´´´ TypeError: Could not convert argument of type symbol to string. at webidl.converters.DOMString (node:internal/deps/undici/undici:1977:15) at webidl.converters.ByteString (node:internal/deps/undici/undici:1982:35) at Object.record<ByteString, ByteString> (node:internal/deps/undici/undici:1894:30) at webidl.converters.HeadersInit (node:internal/deps/undici/undici:3424:67) at Object.RequestInit (node:internal/deps/undici/undici:1951:21) at new Request (node:internal/deps/undici/undici:4835:34) at getRequest (file:///Users/yfidan/projects/kronos/node_modules/@sveltejs/kit/src/exports/node/index.js:107:9) at file:///Users/yfidan/projects/kronos/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:497:27

I found out that using node > 20.11.1 causes the error I described.

$ nvm use 20.11.1 Now using node v20.15.1 (npm v10.7.0) $ npm run dev

dummdidumm commented 3 months ago

Please provide a link to a repository which reproduces this bug. We can't know what's going on just from looking at two copy-pasted files.

YusufFidan commented 3 months ago

I'm really sorry for the confusion. The repository is a private one, but: I found out, that the problem is caused by basicSsl(). I'll try to figure out why, but this is no issue with svelte. Thanks again.

marwie commented 3 months ago

I have the same issue and it happens both with mkcert and with basic-ssl @YusufFidan what was your solution?

YusufFidan commented 3 months ago

I followed the answer from Big_Boulard to the post: https://stackoverflow.com/questions/73205096/run-sveltekit-dev-with-https

I'm using now mkcert. In vite.config.ts:

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

In package.json


"dev": "vite dev --host hostname.ddev.site --port 8443",
´´´

I removed basicssl() completete.
marwie commented 3 months ago

I came to the same solution :) proxy: { } made it work in the end. I guess it would now also work with basic-ssl but I didnt try again

iva2k commented 2 months ago

I got the same issue, with both basicSsl and with backloop.dev (it's new, and I totally dig it for great DX). I confirm adding proxy: {} fixes it with backloop.dev.

I'm not going back to basicSsl to try the fix, but basicSsl has the same underlying mechanics of providing server object certs, so proxy: {} should fix it too.