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

prerendered assets are stored without file ending #9560

Closed
ivanhofer opened this issue Mar 30, 2023 · 4 comments · Fixed by #9692
Closed

prerendered assets are stored without file ending #9560

ivanhofer opened this issue Mar 30, 2023 · 4 comments · Fixed by #9692

Comments

@ivanhofer
Copy link
Contributor

Describe the bug

When prerender set to true and a +page.ts file makes a fetch request, the response of that request get's written to disk.
But it does so without a file ending. So when making a request to /api and /api/child the first response get's saved as
/api (file) and when it tires to save the second response, an error get's thrown because SvelteKit tries to create the /api folder to save the /api/child file.

Reproduction

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

Running npm run build will throw an error.

[Error [ENOTDIR]: ENOTDIR: not a directory, mkdir '/home/projects/sveltejs-kit-template-default-vrpjqd/.svelte-kit/output/prerendered/dependencies/api'] {
  syscall: 'mkdir',
  errno: -20,
  code: 'ENOTDIR',
  path: '/home/projects/sveltejs-kit-template-default-vrpjqd/.svelte-kit/output/prerendered/dependencies/api'
}

Logs

No response

System Info

`StackBlitz`

Severity

blocking an upgrade

Additional Information

No response

@ivanhofer
Copy link
Contributor Author

ivanhofer commented Mar 30, 2023

Workaround for now:

  • don't use nested API endpoints
    /api => /api/root
    /api/child can stay
    or
  • include a . in the route
    /api => /api.json
    /api/child => /api/child.json

@Rich-Harris
Copy link
Member

FWIW we call this out in the docs already: https://kit.svelte.dev/docs/page-options#prerender-route-conflicts

I don't think there's any way around this. We can't just change the name of the saved files, because if /api is saved as <output>/api.json, someone accessing /api directly (whether via a fetch in their app, or by typing it into the URL bar) will get a 404. .html is the exception (and even then, some webservers need extra configuration before treating <output>/foo.html as /foo).

All we can do is detect the error and guide the developer towards a resolution

@Rich-Harris
Copy link
Member

#9692

Rich-Harris added a commit that referenced this issue Apr 17, 2023
…closes #9560 (#9692)

Co-authored-by: Rich Harris <git@rich-harris.dev>
@ivanhofer
Copy link
Contributor Author

Thanks for adding the error message and guiding to the docs!
I haven't seen this section before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants