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

Asset path is wrongly relative to the user’s root not the root of the output when it built on windows system. #13406

Closed
7 tasks done
emosheeep opened this issue Jun 2, 2023 · 4 comments
Labels
duplicate This issue or pull request already exists p2-edge-case Bug, but has workaround or limited in scope (priority) windows only

Comments

@emosheeep
Copy link
Contributor

Describe the bug

I was developing a plugin aims to reflect virtual file into the ouput, but I found there's something wrong with it on windows.

Here is my config where I customize a simple plugin to proxy virtual file fruit/index.html.

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import fs from 'fs'

const virtualFile = 'fruit/index.html'

// https://vitejs.dev/config/
export default defineConfig({
  base: './', // The problem is here.
  plugins: [
    vue(),
    {
      name: 'test-plugin',
      resolveId(id) {
        return id === virtualFile
          ? virtualFile
          : undefined
      },
      load(id) {
        return fs.readFileSync(
          id === virtualFile
            ? 'index.html'
            : id,
          'utf-8'
        )
      }
    }
  ],
  build: {
    rollupOptions: {
      input: virtualFile
    }
  }
})

When I set base to '' or './', the problem occurs. I tried to reproduce it on Mac OS but failed, everything works well.

Reproduction

https://stackblitz.com/edit/vitejs-vite-mhjhr4

Steps to reproduce

Just uses yarn create vite to create a new project on window system and use config provided above to build, you'll get a weird result in which the fruit/index.html looks like:

dist/fruit/index.html

System Info

System:
  OS: Windows 10 10.0.19045
  CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
  Memory: 9.09 GB / 15.76 GB
Binaries:
  Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
  npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
Browsers:
  Edge: Spartan (44.19041.1266.0), Chromium (113.0.1774.57)
  Internet Explorer: 11.0.19041.1566

Used Package Manager

pnpm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Jun 2, 2023

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

@sapphi-red
Copy link
Member

It seems using path.resolve('fruit/index.html') instead of 'fruit/index.html' works as a workaround.

related: #9771, #9793

@sapphi-red sapphi-red added windows only p2-edge-case Bug, but has workaround or limited in scope (priority) labels Jun 2, 2023
@emosheeep
Copy link
Contributor Author

emmm even though, will it be fixed in the future?

@sapphi-red
Copy link
Member

Taking a second look, it seems the problem is that you are resolving the id as non-abosolute id. Vite's internal build-html plugin only expects absolute ids.

I'll close this one as a duplicate of #9662.

@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@sapphi-red sapphi-red added the duplicate This issue or pull request already exists label Nov 8, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists p2-edge-case Bug, but has workaround or limited in scope (priority) windows only
Projects
None yet
Development

No branches or pull requests

2 participants