Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Path separators issue in fs.readdir #172

Closed
dizlexik opened this issue Jul 24, 2017 · 3 comments
Closed

Path separators issue in fs.readdir #172

dizlexik opened this issue Jul 24, 2017 · 3 comments

Comments

@dizlexik
Copy link

I've been trying to get a Next.js project working with pkg and I've finally tracked down the issue to fs.readdir being called in glob.

On Windows locally each of these works: fs.readdirSync('C:\\somedir') and fs.readdirSync('C:/somedir')

But in my pkg Windows executable the second of these fails: fs.readdirSync('C:\\snapshot') and fs.readdirSync('C:/snapshot')

I receive this error message: Error: ENOENT: no such file or directory, scandir 'C:\snapshot'

@dizlexik
Copy link
Author

I dug into this a little bit more and wrote a small hack that is working for me. It's just a workaround for now since I don't have the time to figure out the right way to do this and make a proper PR, but here's the change I made. Hopefully this will help someone fix it the right way.

In /prelude/bootstrap.js I made the following changes to get this to work on Windows:

fs.readdir = function (path) {
  var isRoot = isRootPath(path);

  // <hack>
  if (windows) arguments[0] = path = path.replace(/\//g, '\\');
  // </hack>

  if (!insideSnapshot(path) && !isRoot) {
    return ancestor.readdir.apply(fs, arguments);
  }
  if (insideMountpoint(path)) {
    return ancestor.readdir.apply(fs, translateNth(arguments, 0, path));
  }

  var callback = dezalgo(maybeCallback(arguments));
  readdirFromSnapshot(path, isRoot, callback);
};

And I copied the same line to fs.readdirSync.

I'm hoping a fix for this can make it into the next version because I'm running this in CI and can't easily include my hack there. If I can be of anymore help please let me know. Thanks!

@igorklopov
Copy link
Contributor

Thanks! Going to fix now

xdevs23 pushed a commit to xdevs23/pkg that referenced this issue Jul 26, 2017
@igorklopov
Copy link
Contributor

Fixed in [email protected]

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants