Skip to content

the require-cache-Behavior of windows WHEN using lower-case-diskname : duplicated module(from same file) IN require.cache #54132

Open
@navegador5

Description

Version

v22.1.0.

Platform

PS D:\> echo "$([Environment]::OSVersion.VersionString) $(('x86', 'x64')[[Environment]::Is64BitOperatingSystem])"
Microsoft Windows NT 10.0.22631.0 x64

Subsystem

No response

What steps will reproduce the bug?

suppose we have a simple script fake-module.js under C:\Users\dli>:
console.log("fake-module loaded:",{ __filename: __filename, __dirname: __dirname });

`
Microsoft Windows [版本 10.0.22631.3880]

C:\Users\dli>dir | findstr fake
2024/07/31 12:37 95 fake-module.js
C:\Users\dli>

----------------【noctice the disk name is UPPER-case C:】---------

C:\Users\dli>node
Welcome to Node.js v22.1.0.
Type ".help" for more information.

/*
var mod0 = require("./fake-module");
var mod1 = require("C:\Users\dli\fake-module.js");
var mod2 = require("c:\Users\dli\fake-module.js");
*/

var mod0 = require("./fake-module");
fake-module loaded: {
__filename: 'C:\Users\dli\fake-module.js',
__dirname: 'C:\Users\dli'
}

var mod1 = require("C:\Users\dli\fake-module.js");
undefined
var mod2 = require("c:\Users\dli\fake-module.js");
fake-module loaded: {
__filename: 'c:\Users\dli\fake-module.js',
__dirname: 'c:\Users\dli'
}
mod0 === mod1
true
mod0 === mod2
false

Object.keys(require.cache)
[ 'C:\Users\dli\fake-module.js', 'c:\Users\dli\fake-module.js' ]

-----------【noctice the disk name is LOWER-case c:】---------

BUT if some scripts USE cd "c:\Users\dli", such as:

cd "c:\Users\dli"
c:\Users\dli>

Welcome to Node.js v22.1.0.
Type ".help" for more information.

/*
var mod0 = require("./fake-module");
var mod1 = require("C:\Users\dli\fake-module.js");
var mod2 = require("c:\Users\dli\fake-module.js");
*/

var mod0 = require("./fake-module");
fake-module loaded: {
__filename: 'c:\Users\dli\fake-module.js',
__dirname: 'c:\Users\dli'
}

var mod1 = require("C:\Users\dli\fake-module.js");
fake-module loaded: {
__filename: 'C:\Users\dli\fake-module.js',
__dirname: 'C:\Users\dli'
}

var mod2 = require("c:\Users\dli\fake-module.js");
undefined
mod0 === mod1
false
mod0 === mod2
true

Object.keys(require.cache)
[ 'c:\Users\dli\fake-module.js', 'C:\Users\dli\fake-module.js' ]

`

How often does it reproduce? Is there a required condition?

always

What is the expected behavior? Why is that the expected behavior?

I think when require IF os.platform() is windows: for disk-name, it should case-insensitive.

What do you see instead?

duplicate modules

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaderswindowsIssues 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