Resolver tries to access absolute paths and crashes #12523
Closed
Description
Describe the bug
When trying to access a path in a vite project which corresponds to an absolute path on your local disk, but is unreadable by the current users, vite crashes with an EACCESS
error.
Ideally, Vite should not try to access absolute paths anywhere in the system. But at the least, it should catch EACCESS
errors and know that it the tried path is invalid.
Reproduction
N/A
Steps to reproduce
- Be on a Linux system and have a directory
/recovery
which is only readable by theroot
user - Create a basic vite project
npm create vite@latest test
andnpm run dev
it - Try to access
http://localhost:<port>/recovery
path
System Info
System:
OS: Linux 6.2 Pop!_OS 22.04 LTS
CPU: (32) x64 13th Gen Intel(R) Core(TM) i9-13900K
Memory: 46.10 GB / 62.54 GB
Container: Yes
Shell: 5.1.16 - /bin/bash
Binaries:
Node: 18.15.0 - /usr/bin/node
Yarn: 1.22.17 - /usr/bin/yarn
npm: 9.5.0 - /usr/bin/npm
Browsers:
Chrome: 110.0.5481.96
Firefox: 111.0
Used Package Manager
npm
Logs
12:00:54 AM [vite] Internal server error: EACCES: permission denied, realpath '/recovery/package.json'
at realpathSync.native (node:fs:2644:3)
at loadPackageData (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22177:37)
at tryResolveFile (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22883:33)
at tryFsResolve (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22862:16)
at Context.resolveId (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:22731:24)
at Object.resolveId (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:43314:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async ModuleGraph.resolveUrl (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:61580:26)
at async ModuleGraph.getModuleByUrl (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:61437:23)
at async doTransform (file:///tmp/test/test/node_modules/vite/dist/node/chunks/dep-79892de8.js:41010:20)
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.