vitejs / vite

Next generation frontend tooling. It's fast!
http://vite.dev
MIT License
68.38k stars 6.17k forks source link

Vite dev returns 404 HTTP status error when the project name has the '%20' charcode in the name #8904

Open vinibiavatti1 opened 2 years ago

vinibiavatti1 commented 2 years ago

Describe the bug

Hello. I'm here to report a bug that I found using Vite.

History

I had cloned a personal project that was configured to use Vite for build and serve the solution. After cloned this project, I ran the vite dev to start the application, but after enter in http://localhost:3000, it returned 404 error. When I tried to find other resources that was present in the /public folder, like http://localhost:3000/favicon.ico it returned successfully.

NOTE: By using tsc && vite build and running the vite preview command, the project worked normally. The problem was only with the vite dev command.

After doing some tests to discover the reason for the 404 status by accessing the index.html file, I could not find the solution. The project that I was using with vite was created from npx create-react-app --template typescript boilerplate, and the configuration of the Vite was made by hand. Acording with this, I decided to create a react app by using the Vite CLI, and this project started perfectly. So, by tranfering the resources from the first project to the other one, and testing the result little by little, I got both projects completly equal, with the same configurations, plugins, and dependencies. But, the first one still didn't work, but the second (test project) was working normally.

So, the unique difference of the project was the name of them, one was "My%20Project", and the second one was "test". So, after decided to change the name of the first one removing the charcode %20, the project started working. After putting back the charcode, and ran the vite dev command, the 404 status code was returned again.

Tests

I created some projects using vite, and for any project, when the root folder has the %20 charcode in the name, the 404 HTTP status is shown.

I used the react-scripts for build and serve the solution, and it worked as well.

Steps

  1. Create a new project using npm create vite@latest
  2. Keep the suggestion name
  3. Select vanilla for the framework
  4. Select vanilla for the variant
  5. Rename the name of the generated project folder from vite-project to vite%20project
  6. Open the folder
  7. Execute npm install to install the dependencies
  8. Execute npm run dev to run the app
  9. Access the http://localhost:3000/
  10. Check if the HTTP status returned is 404 (Not Found)

Stack Overflow Top: https://stackoverflow.com/questions/72834388/vite-with-create-react-app-is-returning-404-error/72848313#72848313

Reproduction

Cannot reproduce via vite.new

System Info

System:
    OS: Windows 10 10.0.22000
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
Memory: 18.92 GB / 31.79 GB
    Binaries:
    Node: 16.15.1 - C:\Node\node-v16.15.1-win-x64\node.EXE
    npm: 8.11.0 - C:\Node\node-v16.15.1-win-x64\npm.CMD
Browsers:
    Edge: Spartan (44.22000.120.0), Chromium (103.0.1264.37)
    Internet Explorer: 11.0.22000.120
npmPackages:
    vite: ^2.9.9 => 2.9.13

Used Package Manager

npm

Logs

Click to expand! ```shell PS C:\Users\USER\Desktop\Vite Tests\vite%20project> npm run dev npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead. > vite-project@0.0.0 dev > vite --debug vite:config no config file found. +0ms vite:config using resolved config: { vite:config root: 'C:/Users/USER/Desktop/Vite Tests/vite%20project', vite:config base: '/', vite:config mode: 'development', vite:config configFile: undefined, vite:config logLevel: undefined, vite:config clearScreen: undefined, vite:config server: { vite:config preTransformRequests: true, vite:config fs: { strict: true, allow: [Array], deny: [Array] } vite:config }, vite:config configFileDependencies: [], vite:config inlineConfig: { vite:config root: undefined, vite:config base: undefined, vite:config mode: undefined, vite:config configFile: undefined, vite:config logLevel: undefined, vite:config clearScreen: undefined, vite:config server: {} vite:config }, vite:config resolve: { dedupe: undefined, alias: [ [Object], [Object] ] }, vite:config publicDir: 'C:\\Users\\USER\\Desktop\\Vite Tests\\vite%20project\\public', vite:config cacheDir: 'C:\\Users\\USER\\Desktop\\Vite Tests\\vite%20project\\node_modules\\.vite', vite:config command: 'serve', vite:config isWorker: false, vite:config isProduction: false, vite:config plugins: [ vite:config 'vite:pre-alias', vite:config 'alias', vite:config 'vite:modulepreload-polyfill', vite:config 'vite:resolve', vite:config 'vite:optimized-deps', vite:config 'vite:html-inline-proxy', vite:config 'vite:css', vite:config 'vite:esbuild', vite:config 'vite:json', vite:config 'vite:wasm', vite:config 'vite:worker', vite:config 'vite:asset', vite:config 'vite:define', vite:config 'vite:css-post', vite:config 'vite:worker-import-meta-url', vite:config 'vite:client-inject', vite:config 'vite:import-analysis' vite:config ], vite:config build: { vite:config target: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ], vite:config polyfillModulePreload: true, vite:config outDir: 'dist', vite:config assetsDir: 'assets', vite:config assetsInlineLimit: 4096, vite:config cssCodeSplit: true, vite:config cssTarget: [ 'es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1' ], vite:config sourcemap: false, vite:config rollupOptions: {}, vite:config minify: 'esbuild', vite:config terserOptions: {}, vite:config write: true, vite:config emptyOutDir: null, vite:config manifest: false, vite:config lib: false, vite:config ssr: false, vite:config ssrManifest: false, vite:config reportCompressedSize: true, vite:config chunkSizeWarningLimit: 500, vite:config watch: null, vite:config commonjsOptions: { include: [Array], extensions: [Array] }, vite:config dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] } vite:config }, vite:config preview: { vite:config port: undefined, vite:config strictPort: undefined, vite:config host: undefined, vite:config https: undefined, vite:config open: undefined, vite:config proxy: undefined, vite:config cors: undefined, vite:config headers: undefined vite:config }, vite:config env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false }, vite:config assetsInclude: [Function: assetsInclude], vite:config logger: { vite:config hasWarned: false, vite:config info: [Function: info], vite:config warn: [Function: warn], vite:config warnOnce: [Function: warnOnce], vite:config error: [Function: error], vite:config clearScreen: [Function: clearScreen], vite:config hasErrorLogged: [Function: hasErrorLogged] vite:config }, vite:config packageCache: Map(0) {}, vite:config createResolver: [Function: createResolver], vite:config optimizeDeps: { vite:config esbuildOptions: { keepNames: undefined, preserveSymlinks: undefined } vite:config }, vite:config worker: { vite:config format: 'iife', vite:config plugins: [ vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object], [Object], vite:config [Object] vite:config ], vite:config rollupOptions: {} vite:config } vite:config } +12ms vite v2.9.13 dev server running at: > Local: http://localhost:3000/ > Network: use `--host` to expose ready in 149ms. vite:deps scanning for dependencies... { timestamp: true } +0ms vite:deps Crawling dependencies using entries: vite:deps C:/Users/USER/Desktop/Vite Tests/vite%20project/index.html +0ms vite:resolve 0.93ms /main.js -> C:/Users/USER/Desktop/Vite Tests/vite%20project/main.js +0ms vite:deps Scan completed in 39.91ms: {} +29ms vite:deps dependencies found: { timestamp: true } +41ms vite:deps ✨ optimized dependencies unchanged { timestamp: true } +4ms vite:spa-fallback Rewriting GET / to /index.html +0ms vite:time 3.77ms /index.html +0ms ```

Validations

sapphi-red commented 2 years ago

related: #5194

BOLT04 commented 2 years ago

Hi @sapphi-red, could you help with this issue (and the related one)? Maybe it's in some file where the file path gets resolved, some util function that needs to take into account %20?

Komsomol commented 1 year ago

This issue is still active. Had a project with %20 in the title and the vite dev did not work with 404 returned.

Marinov95 commented 1 year ago

Issue is still active as of 1st of August

ShinnyD commented 1 year ago

Issue still active as of 23rd of August 2033. Was a bit frustrating but thanks for the solution in the meantime!

pablopelardas commented 1 year ago

Still active, It took some time but this solve it for me, thanks!

saulide commented 1 year ago

Same here also with Umlauts: ä,ö etc. Huge problem for me, since i rely on it testing german data

tripolskypetr commented 1 year ago

Still active in September 2023...

steckdev commented 10 months ago

Still happening Jan 2024. Glad this article was here after I cloned a repo from Azure that allows poorly name git projects.

Escanor1986 commented 9 months ago

Hello,

Met the same problem today, a friend told me to comment my root property in vite.config.ts :

import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react';

export default defineConfig({ base: '/', plugins: [react()], // root: './src', (vite seems to do not find my files inside ./src) });

Hope that could help

ozanmanav commented 8 months ago

Is there any fix for this? I think i will return back to CRA :/

geolffreym commented 4 months ago

Hello! Any update about this issue?

devlopersabbir commented 2 weeks ago

I'm also facing the same issue.

when I add that like into my vercel.json file then everything works perfectly 🐸

{
  "rewrites": [
    {
      "source": "/(.*)",
      "destination": "/"
    }
  ]
}

@geolffreym @ozanmanav @steckdev @tripolskypetr

ogwok commented 1 week ago

@devlopersabbir Thank you alot. Adding vercel.json for my vercel deployment worked well. 👍🏿