Skip to content

Mounted Volume in the path causes incorrect resolution output #65

Closed

Description

@chenxinyanc

Minimal repro here: https://github.com/chenxinyanc/unrs-resolver-mounted-partition

When resolving for a module, if there is a mount point instead of ordinary folder within the path of the resolved file, unrs-resolver gives incorrect outputs.

I'm reporting this issue because both eslint-import-resolver-typescript and eslint-plugin-import-x are using unrs-resolver.

Image

For example, suppose there is a Mounted Volume named "mount-root" under current directory, the following code

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { ResolverFactory } from "unrs-resolver";

const resolver = new ResolverFactory({
  tsconfig: {
    configFile: 'tsconfig.json',
  },
});
const dir = path.resolve(fileURLToPath(import.meta.url), '..');
// console.log("dir: ", dir);

const resolved = resolver.sync(dir, './mount-root/foo.ts');
console.log(resolved);

currently prints something like

{
  path: '...\\unrs-resolver-mounted-partition\\src\\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\\foo.ts',
  moduleType: 'module',
  packageJsonPath: '...\\unrs-resolver-mounted-partition\\package.json'
}

where "Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}" is supposed to be "mount-root".

Please refer to the README.md of my reproduction repo attached above for details.

Activity

  1. JounQin commented on Apr 15, 2025

    @JounQin
    Member

    Thanks for the detailed reproduction, it's much appreciated! But I'm sorry I don't have a Windows computer, do you familiar with Rust and want to contribute? That would be great thanks. I may get a Windows VM to work with later.

    By the way, can you help to test does this issue also apply for oxc-resolver?

  2. chenxinyanc commented on Apr 16, 2025

    @chenxinyanc
    ContributorAuthor

    do you familiar with Rust and want to contribute?

    I'm not, unfortunately 🌚

    However, I've just get started and done a bit investigation. I think the issue is with FileSystemOs::read_link(&Path).

    Ok(Self::strip_windows_prefix(path))

    Especially, FileSystemOs::strip_windows_prefix didn't take care of the case where path is an UNC path pointing to a Volume (Drive) without Drive letter, namely, something like this

    \\?\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\
    

    IMO if we were going to resolve the path to its real link target, we should keep this UNC path here as-is, because the path above cannot be furtherly reduced.

    However, nodejs seems still have trouble importing from UNC path directly. I haven't found any explicit statement on whether this is supported, but here are some attempts on Node 22.7.0:

    Welcome to Node.js v22.7.0.
    Type ".help" for more information.
    > const fs = require("fs")
    undefined
    // We cannot import module with UNC path
    > require(String.raw`\\?\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\foo.ts`)
    Uncaught:
    Error: EISDIR: illegal operation on a directory, lstat 'Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\'
        at Object.realpathSync (node:fs:2663:25)
        at toRealPath (node:internal/modules/helpers:53:13)
        at Module._findPath (node:internal/modules/cjs/loader:763:24)
        at Module._resolveFilename (node:internal/modules/cjs/loader:1234:27)
        at Module._load (node:internal/modules/cjs/loader:1074:27)
        at TracingChannel.traceSync (node:diagnostics_channel:315:14)
        at wrapModuleLoad (node:internal/modules/cjs/loader:217:24)
        at Module.require (node:internal/modules/cjs/loader:1339:12)
        at require (node:internal/modules/helpers:126:16) {
      errno: -4068,
      code: 'EISDIR',
      syscall: 'lstat',
      path: 'Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\\'
    }
    // However, things work if we use an ordinary path, even if `mount-root` is a Mounted Volume.
    > require(String.raw`D:\test\unrs-resolver-mounted-partition\src\mount-root\foo.ts`)
    {}
    // Actually we cannot access UNC path of the drive root
    > fs.lstatSync(String.raw`\\?\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}`)
    Uncaught:
    Error: EISDIR: illegal operation on a directory, lstat 'Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\'
        at Object.lstatSync (node:fs:1634:25) {
      errno: -4068,
      code: 'EISDIR',
      syscall: 'lstat',
      path: 'Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\\'
    }
    // We can, however, access UNC path of any files or sub-directories
    > fs.lstatSync(String.raw`\\?\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\foo.ts`)
    Stats {
      dev: 283819367,
      mode: 33206,
      nlink: 1,
      uid: 0,
      gid: 0,
      rdev: 0,
      blksize: 4096,
      ino: 8444249301520764,
      size: 0,
      blocks: 0,
      atimeMs: 1744717190861.8555,
      mtimeMs: 1744717190861.8555,
      ctimeMs: 1744717195891.9143,
      birthtimeMs: 1744717190861.8555
    }
    > fs.lstatSync(String.raw`\\?\Volume{3b0ca266-7f02-4f2c-938c-50931634f3fb}\@azure`)
    Stats {
      dev: 283819367,
      mode: 16822,
      nlink: 1,
      uid: 0,
      gid: 0,
      rdev: 0,
      blksize: 4096,
      ino: 281474976719715,
      size: 0,
      blocks: 8,
      atimeMs: 1744799573976.584,
      mtimeMs: 1725364495016.3733,
      ctimeMs: 1725364495016.3733,
      birthtimeMs: 1678773171142.6729
    }

    Given the status quo of the supportability of the imports with UNC-path, probably we can just treat such symlinks resolved into UNC paths just like ordinary folders. This also aligns with the behavior of enhanced-resolve.

  3. chenxinyanc commented on Apr 16, 2025

    @chenxinyanc
    ContributorAuthor

    By the way, can you help to test does this issue also apply for osc-resolver?

    @JounQin Then I think the issue would probably also apply for osc-resolver. Let's continue the discussion in oxc-project/oxc-resolver/issues/454.

  4. added a commit that references this issue on Apr 25, 2025
  5. added a commit that references this issue on Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions