nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.55k stars 29.58k forks source link

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

Open navegador5 opened 3 months ago

navegador5 commented 3 months ago

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

RedYetiDev commented 2 months ago

Can you check whether this applies to any spot in the path, or specifically the drive letter?