Skip to content

Vite build fails when base option has % #19576

Closed

Description

@albatroez

Describe the bug

When I put a %%%TEMPLATE%%% in the base option in vite.config.js the build starts to fail. This was working before vite v5.4.0.

I'd expect to get a warning but the build still passes. Use case is I'd like to serve multiple versions of the same app with different base urls. The %%%TEMPLATE%%% is later replaced across files with my own script to create those multiple versions. I suppose this could be done with relative path, but should the build fail like that?

Reproduction

https://stackblitz.com/edit/vitejs-vite-jsfwq5kp?file=package.json

Steps to reproduce

Run npm install followed by npm run build

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: 5.4.0 => 5.4.0

Used Package Manager

npm

Logs

Click to expand!
(!) "base" option should start with a slash.
error during build:
URIError: URI malformed
    at decodeURI (<anonymous>)
    at resolveConfig (file:///home/projects/vitejs-vite-jsfwq5kp/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:66263:18)
    at async build (file:///home/projects/vitejs-vite-jsfwq5kp/node_modules/vite/dist/node/chunks/dep-NjL7WTE1.js:65160:18)
    at async CAC.eval (file:///home/projects/vitejs-vite-jsfwq5kp/node_modules/vite/dist/node/cli.js:843:5)e

Validations

Activity

  1. added theissue type on Mar 5, 2025
  2. sapphi-red commented on Mar 10, 2025

    @sapphi-red
    Member

    Vite expects base to be a valid URL and %%%TEMPLATE%%% is not a valid URL. While Vite can probably handle those invalid URLs specially, I think the complexity is too much, given that you can easily workaround this by using a different character than %.

  3. locked and limited conversation to collaborators on Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions