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
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
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:vite/packages/vite/src/node/importGlob.ts
Line 150 in 6bc45a2
baseis the common base (i.e. the directory root) andfileis 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
Used Package Manager
yarn
Logs
Validations