Skip to content

import.meta.glob with {as: "raw"} doesn't handle relative paths #7307

@judofyr

Description

@judofyr

Describe the bug

import.meta.glob("../index.html", { as: "raw" }) fails with an error like "no such file or directory, open '/home/projects/index.html'". This seems to be caused by the following line:

await fsp.readFile(path.join(base, file), 'utf-8')
.

base is the common base (i.e. the directory root) and file is the relative path from the current file. This means that the .. is essentially applied "twice" and Vite is not able find the file.

Reproduction

https://stackblitz.com/edit/vitejs-vite-pvrnsj?file=src/main.js

System Info

2.9.0-beta.0

Used Package Manager

yarn

Logs

Error: Build failed with 1 error:
html:/home/projects/vitejs-vite-pvrnsj/index.html:1:7: ERROR: [plugin: vite:dep-scan] ENOENT: no such file or directory, open '/home/projects/index.html'
    at failureErrorWithLog (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:1557:15)
    at eval (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:1215:28)
    at runOnEndCallbacks (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:1005:63)
    at buildResponseToResult (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:1213:7)
    at eval (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:1322:14)
    at eval (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:637:9)
    at handleIncomingPacket (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:734:9)
    at Socket.readFromStdout (/home/projects/vitejs-vite-pvrnsj/node_modules/esbuild/lib/main.js:604:7)
    at Socket.EventEmitter.emit (https://vitejs-vite-pvrnsj.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:131220)
    at addChunk (https://vitejs-vite-pvrnsj.w.staticblitz.com/blitz.5bca79c80956550a0ee18f24bf5b874e18bb8626.js:6:537045)

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions