Open wvhulle opened 1 year ago
I would like to pass cwd to https://github.com/sveltejs/kit/blob/9259bbad26ae593e82becd74a745214e41f654a9/packages/kit/src/exports/vite/index.js#L113 but it is disabled.
Actually after reading some more, and testing process.cwd, it seems like process.cwd has no effect, so it will have be solved in another way.
It's critical that your app and your config are using the same 'copy' of SvelteKit, otherwise this code, which ensures that error(...)
objects are correctly identified as errors that are safe to display to the user...
...will not work. There are two ways you could do this:
@sveltejs/kit
installed in the project root, not in subapp
etc"@sveltejs/kit": "link:../node_modules/@sveltejs/kit"
(works with pnpm, other package managers will differ)Perhaps there's a way we can detect this situation and throw a useful error.
Hi, thanks! I hadn't thought about that. I will test it out. Meanwhile I forked kit and adapted the sveltekit() vite plugin to also take arguments which solves some of these and related problems.
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
orpnpm 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