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

Build fails on latest Sveltekit 2 and @auth/sveltekit #10332

Closed
subpublic opened this issue Mar 15, 2024 · 3 comments
Closed

Build fails on latest Sveltekit 2 and @auth/sveltekit #10332

subpublic opened this issue Mar 15, 2024 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists svelte

Comments

@subpublic
Copy link

subpublic commented Mar 15, 2024

Environment

System:
OS: macOS 14.3.1
CPU: (8) arm64 Apple M1
Memory: 45.52 MB / 8.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.18.2 - ~/.nvm/versions/node/v18.18.2/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v18.18.2/bin/npm
pnpm: 8.8.0 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 122.0.6261.129
Safari: 17.3.1
npmPackages:
@auth/sveltekit: ^0.14.0 => 0.14.0

Reproduction URL

https://stackblitz.com/edit/sveltejs-kit-template-default-furqfa?file=README.md
or
https://github.com/subpublic/sveltekit2-auth-failing

Describe the issue

Build fails on latest sveltekit and @auth/sveltekit

TypeError: Cannot read properties of undefined (reading 'length')
    at Object.handle (/.svelte-kit/output/server/chunks/hooks.server.js:136:26)
    at respond (/.svelte-kit/output/server/index.js:2603:43)

node:internal/event_target:1033
  process.nextTick(() => { throw err; });
                           ^

How to reproduce

Installing the latest sveltekit 2 demo repo
Installing @auth/sveltekit
Follow usage instructions on
https://authjs.dev/reference/sveltekit
(adding auth.ts and hooks.server.ts)

Expected behavior

Build should succeed

@subpublic subpublic added bug Something isn't working triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Mar 15, 2024
@a0a7
Copy link

a0a7 commented Mar 15, 2024

I have this exact issue as well with Kit version 1.30.4, Svelte version 4.2.12, and TS version 5.3.3.

This is what's responsible:

const action = url.pathname
.slice(
// @ts-expect-error - basePath is defined in setEnvDefaults
_config.basePath.length + 1
)
.split("/")[0]

_config.basePath is not defined here.

@subpublic
Copy link
Author

subpublic commented Mar 16, 2024

Thanks! Good pointer.

Solved it now by adding basePath inside the config

export const { handle, signIn, signOut } = SvelteKitAuth({
	basePath: ''
});

The documentation says it's optional, so should probably have a default setting
https://authjs.dev/reference/core#authconfig

basePath?: string;

@ThangHuuVu
Copy link
Member

ThangHuuVu commented Mar 16, 2024

thanks for reporting this, the issue happens when you have a prerender page export const prerender = true
The default basePath for SvelteKit is /auth BTW. We are working on the issue. I will close this as duplicated of #9809 for now, please continue the discussion there, thank you.

@ThangHuuVu ThangHuuVu added svelte duplicate This issue or pull request already exists and removed triage Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime. labels Mar 16, 2024
@ThangHuuVu ThangHuuVu closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists svelte
Projects
None yet
Development

No branches or pull requests

3 participants