Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

realpath problems on windows #316

Closed
noamokman opened this issue Feb 2, 2019 · 2 comments
Closed

realpath problems on windows #316

noamokman opened this issue Feb 2, 2019 · 2 comments

Comments

@noamokman
Copy link

Hey,
I'm having problems with windows and the realpath function.
It seems that the realpath function always returns the path in a unix format and not windows.

How to reproduce (on windows):

const {resolve} = require('path');
const {vol} = require('memfs');

process.chdir('/');

vol.writeFileSync('package.json', '');

const resolvedPath = resolve('package.json');
const realPath = vol.realpathSync(resolvedPath);

console.log(realPath); // '/package.json'
console.log(resolvedPath); // 'D:\\package.json'

What can I do?

@G-Rath
Copy link
Collaborator

G-Rath commented Jul 17, 2019

You can actually manually select what path format the path API uses by using the win32 & posix path properties to call path methods:

path.posix.resolve

I would recommend doing this w/ memfs, as it will clear up a lot of problems, and make everything nicely consistent.

Otherwise, there has been talk on "proper" win32 support via #327 - I've not had a proper read, but I might be willing to make a PR if the proposed solution is all that's needed.

Regardless, personally I found switching to using .posix resolved all my path problems; the Node fs API accepts posixs path correctly regardless of OS :)

@Visual-Dawg
Copy link

Visual-Dawg commented Jul 9, 2022

@G-Rath The problem I have is that memfs cuts out the drive letter and in this example (and in my case), it is not the default drive C:/ which gets accessed. And Windows automatically thinks that a path without a drive letter should get resolved to C:/.
Am I understanding something wrong or is there a way around that?

Edit: Also how can I use posix.resolve with external drives?
Edit2: Replacing resolve with join seems like a good way to deal with resolve. I have not found a solution for the drive letters and memfs though.

Okay, using join also works perfectly with memfs. Thank you also for creating this awesome library!

@G-Rath G-Rath closed this as not planned Won't fix, can't repro, duplicate, stale Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants