Skip to content

throw error(500, message) results in "internal error" instead of message when sveltekit() is called elsewhere #9029

@wvhulle

Description

@wvhulle

Describe the bug

I have a monorepo with several sveltekit subprojects. To recycle my setup I have created a viteconfig that is share among the subprojects. This viteconfig is not inside the same directory as svelte.config.js.

To see the error, execute npx run dev or pnpm exec vite dev. The internal error that you can see in the browser should not be displayed. Instead, the user provided error should be shown.

The bug disappears when sveltekit() is called inside the root directory (as would be the case in the default setup). Looking into the source code, the function sveltekit or load_config depends on the cwd. However, changing the cwd before calling sveltekit() does change the error. Instead of showing the error in the browser using the fallback error page, the browser displays "internal error" and the terminal window show that the server outputs "undefined" when the error is thrown.

This bug means that I have to duplicate my vite config across different subprojects in a monorepo because the sveltekit() function does not follow cwd (when it comes to errors). It seems like other things, apart from the sveltekit error, run.

Reproduction

https://github.com/wvhulle/sveltekit-error-page-vite-plugin

Logs

wvhulle@work ~/D/s/subapp (master) [1]> pnpm run dev

> sveltekit-error-page-vite-plugin@0.0.1 dev /home/wvhulle/Documents/sveltekit-error-page-vite-plugin/subapp
> vite dev



  VITE v4.1.1  ready in 1620 ms

  ➜  Local:   http://localhost:3000/
  ➜  Network: use --host to expose
  ➜  press h to show help
undefined
undefined
2:30:08 PM [vite-plugin-svelte] ssr compile done.
package                         	files	  time	   avg
sveltekit-error-page-vite-plugin	    1	29.0ms	29.0ms
@sveltejs/kit                   	    2	 3.9ms	 1.9ms
undefined


### System Info

```Shell
System:
    OS: Linux 5.15 Linux Mint 21.1 (Vera)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1145G7 @ 2.60GHz
    Memory: 6.90 GB / 15.36 GB
    Container: Yes
    Shell: 3.5.1 - /usr/bin/fish
  Binaries:
    Node: 19.4.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.2.0 - /usr/local/bin/npm
  Browsers:
    Chromium: 109.0.5414.119
    Firefox: 109.0.1
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.0.0 
    @sveltejs/kit: ^1.5.0 => 1.5.6 
    svelte: ^3.54.0 => 3.55.1 
    vite: ^4.0.0 => 4.1.1 


### Severity

annoyance

### Additional Information

I suspect that this bug could be solved with the possibility of an inline config in vite.
https://github.com/sveltejs/kit/issues/5485
However, since changing the cwd does not solve this and the rest keeps working, I suspect this is related more to the implementation of the throw error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions