sveltejs / kit

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

request route with param and folder in static with same name returns error on dev mode #5791

Open CordlessWool opened 2 years ago

CordlessWool commented 2 years ago

Describe the bug

In the project, I have a route and a folder in static with the same name (images). Loading images/someimage.jpg working well, but accessing just images?somepaream produce an error.

Failed to load url /images?load=%2Fimages%2Fteaser.jpg (resolved id: /images?load=%2Fimages%2Fteaser.jpg). This file is in /public and will be copied as-is during build without going through the plugin transforms, and therefore should not be imported from source code. It can only be referenced via HTML tags.

Seems relating to https://github.com/sveltejs/kit/issues/5672 but in a more special way. After build there is no problem, only in dev mode I get this error.

Reproduction

https://stackblitz.com/edit/sveltejs-kit-template-default-yefxpo?file=src/routes/index.svelte

Logs

9:05:21 PM [vite] Internal server error: Failed to load url /images?load=%2Fimages%2Fteaser.jpg (resolved id: /images?load=%2Fimages%2Fteaser.jpg). This file is in /public and will be copied as-is during build without going through the plugin transforms, and therefore should not be imported from source code. It can only be referenced via HTML tags.
      at loadAndTransform (file:///home/wolle/Workspace/vally/node_modules/vite/dist/node/chunks/dep-71eb12cb.js:39798:19)
      at processTicksAndRejections (node:internal/process/task_queues:96:5) (x2)

System Info

System:
    OS: Linux 5.18 Fedora Linux 36 (Workstation Edition)
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
    Memory: 8.51 GB / 15.35 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.16.0 - ~/.nvm/versions/node/v16.16.0/bin/node
    npm: 8.11.0 - ~/.nvm/versions/node/v16.16.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Firefox: 102.0

Severity

serious, but I can work around it

Additional Information

No response

benmccann commented 2 years ago

It would be helpful to know if this happens with a plain Vite project or only with SvelteKit: https://github.com/sveltejs/kit#bug-reporting

CordlessWool commented 2 years ago

What I currently know is that it didn't happen with a version of sveltekit before 39x. I do not have the exact version in mind.

CordlessWool commented 2 years ago

I tried to rebuild it with vite vanilla, but I never did a project with vite beside svelte kit so I am not sure if I test it correctly, but I didn't get an error.

I created a project with npm create vite-extra@latest -- --template ssr-svelte

Afterwards I added a route in server.js for GET requests on /imagesand I created a folder images in public. It toke the server route and didn't throw an error. So for me it looks like everything is ok in vite.

dummdidumm commented 1 year ago

I'm pretty sure this is a Vite issue - our code correctly determines that this is not a static asset since it's a directory, then calls the next middleware which happens to be Vite's which then throws the error.