Skip to content

SvelteKit alternative hooks path resolving problem #13184

@p4wn-dev

Description

@p4wn-dev

Describe the bug

I have defined an alternative path for my server hook file in svelte.config.js, which is

[....]
files: { hooks: { server: 'src/hooks/hooks.server' } }
[....]

Since updating SvelteKit this does not work anymore and I get an internal server error. I provided the stack trace.
After tinkering around I found that if you create an empty universal hook file and add it to svelte.config.js like this:

files: { hooks: { server: 'src/hooks/hooks.server', universal: 'src/hooks/hooks' } }

Then it works.
Strangely adding a client hooks file does not work, only with a universal hooks file.

Did something change recently that I missed? I could not find anything related to this.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-llqwvuwy

Logs

Error: Failed to load url /src/hooks (resolved id: /src/hooks). Does the file exist?
    at loadAndTransform (file:///<project_path>/node_modules/vite/dist/node/chunks/dep-yUJfKD1i.js:40842:17) {
  code: 'ERR_LOAD_URL',
  runnerError: Error: RunnerError
      at reviveInvokeError (file:///<project_path>/node_modules/vite/dist/node/module-runner.js:545:18)
      at Object.invoke (file:///<project_path>/node_modules/vite/dist/node/module-runner.js:628:15)
      at async SSRCompatModuleRunner.getModuleInformation (file:///<project_path>/node_modules/vite/dist/node/module-runner.js:1200:73)
      at async request (file:///<project_path>/node_modules/vite/dist/node/module-runner.js:1222:88)
      at async get_hooks (<project_path>/.svelte-kit/generated/server/internal.js:44:28)
      at async eval (<project_path>/node_modules/@sveltejs/kit/src/runtime/server/index.js:82:20)
      at async Server.init (<project_path>/node_modules/@sveltejs/kit/src/runtime/server/index.js:80:3)
      at async file:///<project_path>/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:489:5

System Info

System:
    OS: Windows 10 10.0.19045
    CPU: (8) x64 Intel(R) Xeon(R) W-2225 CPU @ 4.10GHz
    Memory: 10.87 GB / 31.69 GB
  Binaries:
    Node: 22.6.0
    npm: 10.9.2
  Browsers:
    Edge: Chromium (131.0.2903.99)
  npmPackages:
    @sveltejs/adapter-auto: ^3.0.0 => 3.3.1
    @sveltejs/adapter-node: ^5.2.9 => 5.2.10
    @sveltejs/kit: ^2.9.0 => 2.12.1
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.2
    svelte: ^5.0.0 => 5.14.1
    vite: ^6.0.0 => 6.0.3

Severity

annoyance

Additional Information

UPDATE: Can confirm that the issue occurs from version 2.11.0 upwards.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions