ViteJS doesn't seem to properly resolve symlinks
See original GitHub issue- Read the docs.
- Make sure this is a Vite issue and not a framework-specific issue.
- This is a concrete bug.
Describe the bug
ViteJs doesn’t properly resolve symlinks.
Reproduction
Repro repo: https://github.com/dbismut/preconstruct-repro
After installing dependencies, please run yarn vite
.
See comment here for hint at a solution. https://github.com/preconstruct/preconstruct/issues/378#issuecomment-789681043
Relevant bit from comment
We might notice here that the importer is in the
dist
directory - but it’s actually a linked file and thus it should be resolved to the real path (in the src directory). This is IMHO a problem with Vite’s resolver as this works correctly with most of the popular tools. This particular issue can be fixed by adjusting the body of this condition: https://github.com/vitejs/vite/blob/39820b96cec2c672e849e160b92b42c979b85285/packages/vite/src/node/plugins/resolve.ts#L348-L355 to:
resolved = fs.realpathSync(resolved)
return { id: resolved }
but I’m not super convinced that this is the appropriate place for the fix - the resolving logic in Vite is quite complex and has some layers. So it would really be best for them to assess at what level this should be fixed. It’s also worth noting that it might be worthwhile to use fs.realpathSync.native if it’s available in the given node version.
System Info
vite
version: 2.0.5- Operating System: MacOS 11.2.2
- Node version: 12.8.4
- Package manager (npm/yarn/pnpm) and version: yarn 2.4.1
Logs (Optional if provided reproduction)
- Run
vite
orvite build
with the--debug
flag. - Provide the error log here.
[vite] Internal server error: Failed to resolve import "./data". Does the file exist?
Plugin: vite:import-analysis
File: /Users/david/repos/preconstruct-repro/packages/a/dist/myrepo-a.esm.js
1 | import { data } from "./data";
| ^
2 |
3 | export function fn1() {
at formatError (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45829:46)
at TransformContext.error (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:45825:19)
at normalizeUrl (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:47321:26)
at async TransformContext.transform (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:47450:57)
at async Object.transform (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:46027:30)
at async transformRequest (/Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61631:29)
at async /Users/david/repos/preconstruct-repro/node_modules/vite/dist/node/chunks/dep-e0f09032.js:61739:32
vite:time 7ms Users/david/repos/preconstruct-repro/packages/a/dist/myrepo-a.esm.js +22ms
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:6
Top GitHub Comments
I just tried with Vite 2.1.0 and the issue persists.
https://github.com/vitejs/vite/pull/4708 was just merged, which should fix this