I have a JS project - Vite - on my D:\
drive.
D:\
is a mapped drive pointing to C:\Users\<UserName>\Work
.
Now, if my working directory is the C:\
based one, npx vite build
runs successfully, and I can see its generated config file has {root: "C:/..."}
.
However, if my working directory is the D:\
based one, npx vite build
fails, because the generated config file has {root: "D:/..."}
, and the error message indicates that's not withint C:\
.
Thus, Vite, under the hood, resolves the mapped D:\
drive into C:\Users\<UserName>\Work
, thus it uses the real location not the linked one.
How can I translate the mapped drive, how can I resolve the real location, using node
's file system methods? (Or in worst case, CLI which works both on windows and linux)
I want to have an own vite.config
file with {root: "C:/..."}
instead of {root: "D:/..."}
- I tested hard coding the C:/
based root
, it works!
Interesting, because I've found in Vite's source code it uses process.cwd()
to calculate root
, tried it in my own vite.config.ts
, but gave me D:/
.
Even creepier, if I create an own vite.config.ts
and call to the method I've found Vite uses if there is no custom vite.config
file provided, it still gives me D:/
:
export default defineConfig(({command, mode, isPreview, isSsrBuild}: ConfigEnv): Promise<UserConfig> => {
return resolveConfig({configFile: false}, command, mode, mode);
});
But if I put a console.trace();
into Vite's source code when I don't have a vite.config
, I can see resolveConfig
is called, and root
will be C:/
.
Can't figure out how is this possible...
Anyway, my question is the bold one above, this is just the part describing what I've tried so far.
fs.realpathSync.native(__dirname)
- I've found the answer in this Vite issue - just after writing the essay in the question...