Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in vite.config.ts #12139

Closed
msprada opened this issue Apr 19, 2024 · 1 comment

Comments

@msprada
Copy link

msprada commented Apr 19, 2024

Describe the bug

First of all I'm not 100% sure if this "defect" is caused by Vite or Svelte Kit. But I decided to go for a issue in the svelte kit repo. If this is related to Vite and the Svelte Kit Team cannot handle it, I will definitely open the ticket or transfer the ticket to the other Repo.

Update 07/08/2024:
In the meantime I created an issue for the vite team as well => vitejs/vite#17631.

I search for similar bugs within the list and for sure within the www, but I could not find any ones.
Maybe it is related to this instance of Redirect Check wich was mentioned here => Redirects in load functions break when running client-side #5952

Situation:

  • I created a pnpm workspace including one application which provides a REST API (nestJS) and the second application which includes the svelte kit ui. Furthermore I have packages which includes all shared libraries e.g a lib for the dtos, models. etc.

To be able to reference the models library in the svelte application I added a symlink within the packages.json in the way pnpm wants it to be: "data-access-models": "workspace:*"

"dependencies":
 {
	"@lucia-auth/adapter-sqlite": "^3.0.1",
	"arctic": "^1.5.0",
	"better-sqlite3": "^9.5.0",
	"data-access-models": "workspace:*",
	"esm-env": "^1.0.0",
	"oslo": "^1.2.0"
},

So I can use this importing in my pages and components "page.svelte":

<script lang="ts"> import { OrderDto } from 'data-access-models'; export let data; const orders: OrderDto[] = data.orders; </script>

Without further changes with in the application this resulted in following error:

image

To get this working I had to change the vite.config extend the "resolve" part which results in following.


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

export default defineConfig({
	plugins: [sveltekit()],
	test: {
		include: ['src/**/*.{test,spec}.{js,ts}']
	},
	resolve: {
		preserveSymlinks: true
	}
});

So far so could I could use the models and the component was rendered perfectly.

UPDATE 07/08/24:
In the meantime I build the shared lib as ES as well as commonJS lib and there is no need for symlinks.
But the issue when using preserveSymlinks set to true still exists.
See Discord for details.

Currently I'm implementing authentication and authorization using Lucia Auth.

So there is the need of redirect a user from my homepage if he/she is not logged in.

So I included following file under routes folder "page.server.ts" and implementing the PageServerLoad Method.

export const load: PageServerLoad = async (event) => {
	if (!event.locals.user) {
		console.error('redirect triggered!');
		redirect(302, "/signin");
	}
	return {
		user: event.locals.user
	};
};

If I open my homepage within login into the application the ui shows me a 500 error instead of redirecting me to the /signin route.

Within my server logs I can see following entry:

image

And if navigating to the url /signin the Signin Screen is shown without any problems.

Reproduction

  • to reproduce the behavior visit Following Repo
  • it was newly created and only relevant part is included
  • follow the steps within in the readme.md file which is included in the root folder

Logs

No response

System Info

System:
    OS: macOS 11.7.10
    CPU: (8) x64 Intel(R) Core(TM) i7-4850HQ CPU @ 2.30GHz
    Memory: 437.52 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.nvm/versions/node/v20.10.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.10.0/bin/yarn
    npm: 10.2.3 - ~/.nvm/versions/node/v20.10.0/bin/npm
    pnpm: 8.15.4 - ~/.nvm/versions/node/v20.10.0/bin/pnpm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 123.0.6312.124
    Safari: 16.6.1

Severity

blocking all usage of SvelteKit

Additional Information

If there is anything missing within the description please let me know.

@msprada msprada changed the title Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in site.config.ts Redirects in "PageServerLoad" does result in 500 internal error within in a pnpm workspace if "preserveSymlinks" is used in vite.config.ts Apr 19, 2024
@eltigerchino
Copy link
Member

closing as duplicate of #12597

@eltigerchino eltigerchino closed this as not planned Won't fix, can't repro, duplicate, stale Oct 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants