sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.44k stars 1.89k forks source link

prerendered assets are stored without file ending #9560

Closed ivanhofer closed 1 year ago

ivanhofer commented 1 year ago

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 commented 1 year ago

Workaround for now:

Rich-Harris commented 1 year ago

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 commented 1 year ago

9692

ivanhofer commented 1 year ago

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