Visitar URL original
Add ability to handle win32 relative paths · Issue #401 · webpack/enhanced-resolve · GitHub
Skip to content

Add ability to handle win32 relative paths #401

Open

Description

@davakh

Issue

Right now, based on codebase, library supports only posix relative paths.

Reproduction

This is correct relative path in context of this library:

../../../src

This is incorrect relative path in context of this library:

..\\..\\..\\src

To understand how the library understands these paths, you can call getType from this file:
posix path as Relative; win32 path - as Normal

So, anything that can be passed as a result by path.relative(...) in Node.js, will not work as expected on Windows machines.

Solutions

Possible solution is to add separation in the enum of types for RelativePosix and RelativeWin, like for the Absolute.. paths. But it's hard to predict what integrations with this library are going to break, so I think it can be a big deal.

Workaround

Add replacing for backward compatibility with Windows (Windows can handle posix separator):

path.relative(....).split(path.win32.sep).join(path.posix.sep);

PS. Maybe you want to handle only relative posix paths in this library, and then I think it would be cool to add information about this scenario or to close this issue with a preferable workaround.

Activity

  1. alexander-akait commented on Jan 4, 2024

    @alexander-akait
    Member

    Hello, can you provide a problem/example where you got such paths?

  2. davakh commented on Jan 5, 2024

    @davakh
    Author

    It's possible to get this type of paths when you work with module-federation f.e. Of course, it's overhead to give an example with another library, but I can provide an example with current library via codesandbox.

  3. alexander-akait commented on Jan 22, 2024

    @alexander-akait
    Member

    @davakh Sorry for delay, do you want to send a PR?

  4. moved this to Priority - Medium in webpack 5/6on Jan 22, 2024
  5. davakh commented on Jan 22, 2024

    @davakh
    Author

    Yes, I have some thoughts on how to solve it. I'll try to give a PR in near future.

  6. alexander-akait commented on Apr 21, 2026

    @alexander-akait
    Member

    /cc @xiaoxiaojx What do you think about it? Do we really need to have a support win32 paths request, technically you can use \\ in require.resolve (but not in import.meta.resolve), so I don't think do we really need this

  7. xiaoxiaojx commented on May 3, 2026

    @xiaoxiaojx
    Member

    Sorry for missing this message! This is a subtle issue — passing Node.js path.relative() directly to the resolver works on POSIX but fails on Windows. If the change is small and doesn’t introduce any performance regressions, it might be worth supporting, since the path comes from the official path.relative() API. However, it seems that both oxc-resolver and rspack-resolver don’t support this either. https://github.com/webpack/enhanced-resolve/actions/runs/25276455827/job/74107022461?pr=564.

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

    Fields

    Priority

    None yet

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions