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

building with --base "" results in /0 being used for the base instead #14204

Closed
7 tasks done
JakeIsMeh opened this issue Aug 27, 2023 · 3 comments · Fixed by #14283
Closed
7 tasks done

building with --base "" results in /0 being used for the base instead #14204

JakeIsMeh opened this issue Aug 27, 2023 · 3 comments · Fixed by #14283
Labels
contribution welcome p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@JakeIsMeh
Copy link

Describe the bug

Overview

When doing vite build --base "", the resulting SPA loader has /0/ for all of it's hrefs and srcs.

Expected behaviour

the resulting SPA loader has a base path of / for all of it's hrefs and srcs.

Experienced Behaviour

the resulting SPA loader has a base path of /0/ for all of it's hrefs and srcs.

What I'm trying to do

I use actions/configure-pages@v3 which provides environment information for the workflow, such as the base path for the deployment.

It allows me to avoid specifying the base path in code as it is simply specified at deploy time in the build command like this:

# .github/workflow.yaml
- name: Build with Vite
  run: npx vite build --base "${{ steps.pages.outputs.base_path }}"

However, when deploying to a root base, configure-pages returns the base path as blank and not /, which is allowed as specified in the docs.

This results in a broken build as the SPA loader tries to load assets from domain.tld/0/assets/index-hash.js instead of domain.tld/assets/index-hash.js

Triaging I have done

Only affects vite@^4.3.0 as any older versions would error out when using --base ""
Only affects plain Vite projects, as I have successfully deployed a SvelteKit app using vite build --base "" (Vite 4.4.9)
(I tried with vite.new/vue, vite.new/svelte, vite.new/solid)

Reproduction

https://stackblitz.com/edit/vitejs-vite-gqpqgr?file=dist%2Findex.html

Steps to reproduce

Run npm i followed by npx vite build --base ""

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: 16.20.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 9.4.2 - /usr/local/bin/npm
    pnpm: 8.6.10 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-vue: ^4.2.3 => 4.3.3 
    vite: ^4.4.9 => 4.4.9

Used Package Manager

npm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Aug 27, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@btea
Copy link
Collaborator

btea commented Sep 1, 2023

A warning message has been printed.

image

@bluwy
Copy link
Member

bluwy commented Sep 4, 2023

I guess we can handle this specific case to coerce 0 to "". The changes would be here:

.option('--base <path>', `[string] public base path (default: /)`)

With a similar change as:

.option('--host [host]', `[string] specify hostname`, { type: [convertHost] })

@bluwy bluwy added contribution welcome p2-nice-to-have Not breaking anything but nice to have (priority) and removed pending triage labels Sep 4, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants