Skip to content

On Windows, Node can be inconsistent in what case builtin functions use for drive letters #6624

Closed
@thorn0

Description

@thorn0
  • Version: 6.0.0
  • Platform: Windows 7 x64
  • Subsystem: path, module, process

When cmd.exe is run via a shortcut that has a lowercase drive letter in its 'Start in' field (e.g. d:\dev) and Node is run from this cmd instance, Node's builtin functions behave in an unexpected way. Some of them return the drive letter in upper case (D:\dev\foo) whereas the other in lower (d:\dev\foo).

test.js:

var exprs = ['__dirname', '__filename', 'require.resolve("./test")', 
    'require("path").resolve("test.js")', 'process.cwd()'];
for (var expr of exprs) {
    console.log(expr, eval(expr));
}

In cmd:

d:\dev\foo>node test
__dirname D:\dev\foo
__filename D:\dev\foo\test.js
require.resolve("./test") D:\dev\foo\test.js
require("path").resolve("test.js") d:\dev\foo\test.js
process.cwd() d:\dev\foo

If I change the case of the drive letter in the "Start in" field of the shortcut for cmd, everything becomes consistent.

D:\dev\foo>node test
__dirname D:\dev\foo
__filename D:\dev\foo\test.js
require.resolve("./test") D:\dev\foo\test.js
require("path").resolve("test.js") D:\dev\foo\test.js
process.cwd() D:\dev\foo

This leads to issues like webpack/webpack#2362.

So what can be done about it?

  1. It'd be great if Node always used upper case.
  2. Also now Node resolves d:\test.js and D:\test.js as two different modules. Should it stay like this?
d:\dev\foo>echo console.log('load')>bar.js
d:\dev\foo>node
> require('d:\\dev\\foo\\bar.js')
load
{}
> require('d:\\dev\\foo\\bar.js')
{}
> require('D:\\dev\\foo\\bar.js')
load
{}

Metadata

Metadata

Assignees

No one assigned

    Labels

    moduleIssues and PRs related to the module subsystem.pathIssues and PRs related to the path 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