Description
Describe the bug
(Sorry if this was asked/answered before, just cannot find information on this topic)
When building a simple project, I get dist/index.html
file with relative paths using parent directories navigation (double dots). It looks like this:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="../../../vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite App</title>
<script type="module" crossorigin src="../../../assets/index-BXSNOGaM.js"></script>
<link rel="stylesheet" crossorigin href="../../../assets/index-BfibREyH.css">
</head>
<body>
<div id="app"></div>
</body>
</html>
Seems to be happening when navigating to a subdirectory of the main drive C:
from the default Windows terminal, cmd
and building the project from there. (see the reproduction steps)
The vite.config
has the option base: ''
or base: './'
.
What is expected is the relative paths with only the initial dot, like
<link rel="icon" type="image/svg+xml" href="./vite.svg" />
...
<script type="module" crossorigin src="./assets/index-BXSNOGaM.js"></script>
<link rel="stylesheet" crossorigin href="./assets/index-BfibREyH.css">
This expected result seems to be achieved when creating a project in the C:
drive directly with npm create vue@latest
.
The problem seems to be related to the method of reaching the target directory, though not sure about the exact explanation.
I'd say if you go with cmd.exe /k cd [path]
the index.html
ends with parent folders paths and if you enter into directories one by one, the relative paths start with ./
.
Again, sorry for duplication, surely it happened to someone else, but I just cannot formulate the search request in Google or here in Issues to find an adequate solution. Or if it's not vite related, if you point me to the possible solution it would be greatly appreciated.
Reproduction
https://stackblitz.com/edit/vitejs-vite-dnt7jk
Steps to reproduce
- download the project
- unpack it to
C:\a
folder - open Run dialog (Win+R) and execute
cmd /k cd c:\a
- in the opened terminal run
npm install & npm run build
- open
dist/index.html
in a text editor and see the relative paths contain parent folders navigation (../
)
System Info
System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
Memory: 11.50 GB / 23.76 GB
Binaries:
Node: 20.14.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.22 - c:\Users\user\AppData\Roaming\npm\yarn.CMD
npm: 10.7.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: Chromium (124.0.2478.51)
Internet Explorer: 11.0.19041.4355
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.