Skip to content

require(".\\") doesn't resolve index.js on Windows #18299

Description

@jdalton

While looking at #15015 (comment) I noticed that the trailing slash check in _findPath was only keying off of a forward slash and not the backslash that Windows allows.

You can repro this by simply doing the following in a directory with an index.js

require(".\\") // throws
require("./") // will find the index.js

Other places in Node account for the backslash in Windows paths so this looks like an oversight.

Update:

It looks like if it's a two dot relative path to an index.js then it does work.

require("..\\") // work
require("..\\.") // works
require("../") // works
require("../.") // works

Also this

require("./..") // works
require(".\\..") // throws

Notes:

It looks like path.resolve handles these cases fine so it can be excluded from the problem.

path.resolve(".\\") // 'C:\\projects\\bar\\foo'
path.resolve(".\\..") // 'C:\\projects\\bar'

Activity

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

    moduleIssues and PRs related to the module subsystem.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions