-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Description
Describe the bug
Consider this vite config;
import { defineConfig } from "vite";
import path from "node:path";
export default defineConfig({
resolve: {
alias: [
{
find: "$okay:/",
replacement: path.resolve(__dirname, "src"),
},
{
find: "broke:/",
replacement: path.resolve(__dirname, "src"),
},
],
},
});
When running vite dev
, the alias broke:/
is not transformed and gets caught by the platform module loader.
When running vite preview
, both aliases are transformed and point to the src
directory.
The way these aliases are used is $okay://*
, broke://*
. Apparently a $
prefix is not valid as part of a protocol, so that one gets passed on as expected in dev, however because broke
is valid the module loader in the browser/node tries to load it, and then throws when it realises it can't handle that protocol.
Evidently the broken example ought to work in production, because it does work in production. Imo it also ought to work in development.
Discovered this when I had the thought "hey, I could import my resources from res://*
that could be fun" and tried it out.
Reproduction
https://github.com/Squidgical/vite-issue_resolve.alias
Steps to reproduce
Steps are in the reproduction repo readme.
- run the dev server, observe
- run the preview server, observe
System Info
System:
OS: Linux 6.12 Pop!_OS 22.04 LTS
CPU: (16) x64 AMD Ryzen 9 7940HS w/ Radeon 780M Graphics
Memory: 13.90 GB / 27.21 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 22.18.0 - ~/.nvm/versions/node/v22.18.0/bin/node
npm: 10.9.3 - ~/.nvm/versions/node/v22.18.0/bin/npm
pnpm: 10.13.1 - ~/.local/share/pnpm/pnpm
bun: 1.2.16 - ~/.bun/bin/bun
npmPackages:
vite: ^7.1.2 => 7.1.2
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.