Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

windows: case-insensitive lookup in module cache #6774

Closed
wants to merge 1 commit into from
Closed

windows: case-insensitive lookup in module cache #6774

wants to merge 1 commit into from

Conversation

orangemocha
Copy link
Contributor

The module cache key is the resolved filename which should
be treated as case-insensitive on Windows.

Fixes test-module-loading.js on Windows.

@@ -271,8 +271,9 @@ Module._load = function(request, parent, isMain) {
}

var filename = Module._resolveFilename(request, parent);
var cacheKey = (process.platform === 'win32') ? filename.toLowerCase() : filename;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 column limit, also please remove parens before ternary.

@indutny
Copy link
Member

indutny commented Dec 28, 2013

Generally, LGTM. May I ask you to change Fixes to Fix in commit log?

@orangemocha
Copy link
Contributor Author

I meant "fixes" as the third person of the verb "to fix" :) I can change it to "this fixes"

@indutny
Copy link
Member

indutny commented Dec 28, 2013

It is not about grammar, mostly about style. We use "Fix" form, not "Fixes".

@rlidwka
Copy link

rlidwka commented Dec 28, 2013

Why should it be treated as case-insensitive? Does current implementation cause any real bugs in the code? What would happen if case-sensitive filesystem will be mounted on windows (no idea if it's possible)?

The module cache key is the resolved filename which should
be treated as case-insensitive on Windows.

Fix test-module-loading.js on Windows.
@orangemocha
Copy link
Contributor Author

Updated.
@rlidwka I suppose one could mount NFS (network file system) on Windows server which is case sensitive (even though everything else on WIndows is expected to be case-insensitive when dealing with filenames). If you had two modules whose names only differed by case then you could end up loading one by referencing the other. I doubt this is a scenario we need to worry about though.

@tjfontaine
Copy link

I want to get feedback from @isaacs on this, but I am mostly ok with this.

Is there a way to convince windows api calls to guarantee casing for us, or is it basically always our responsibility?

@orangemocha
Copy link
Contributor Author

Win32 APIs are all case-insensitive with regard to filenames.

@optimuspaul
Copy link

LOL on the "Fix" vs "Fixes" comments.

@jonerer
Copy link

jonerer commented Apr 6, 2014

+1 to get this fixed. Wrote about my experience here: http://jonmrdsj.wordpress.com/2014/04/06/node-js-double-inclusion-on-windows/

Basically, if you do require('./file'); require('./File'), it will load and execute the same file twice, which is not what I expected

@orangemocha
Copy link
Contributor Author

@tjfontaine any good reasons not to take this fix?

@hefangshi
Copy link

Like #7880 says, still think nodejs should make the driver letter to be uppercase to paired with __dirname . The way to normalize driver letter to lower case is just not like windows.

@mgol
Copy link

mgol commented Sep 25, 2014

require('./file'); require('./File')

...and that's not even the biggest issue. Node internal APIs differ in which kind of drive letter to use in 0.11 which can cause a file to be re-evaluated twice even if you didn't specify any file twice in two different ways.

This broke some Grunt public APIs for me; see #7806.

@jasnell
Copy link
Member

jasnell commented Aug 3, 2015

@orangemocha ... is this still needed/relevant?

@orangemocha
Copy link
Contributor Author

@jasnell : still relevant, but since it's been a while I need to take a second look and make sure it's up to date and the best fix for the underlying issue.

@jasnell
Copy link
Member

jasnell commented Aug 27, 2015

@orangemocha ... ok, it looks like @misterdjules submitted an alternate fix to the same problem... #8145

@orangemocha
Copy link
Contributor Author

@jasnell : thanks for the link. I still think we need case normalization, which path.normalize doesn't do. While trying to load the same module with different casing would be most likely a user error, the module will still load, but twice.

@jasnell
Copy link
Member

jasnell commented Sep 1, 2015

+1 .. definitely agree that the case normalization is important.

@FransGH
Copy link

FransGH commented May 14, 2016

Old topic but still a pain if you waste valuable hours of your life troubleshooting non-working singletons..

This is not just a Windows issue, Please have a look at this pull request #8145 that nails it.

Note that there are two issues with require() case sensitivity, #8145 addresses the 2nd:

  1. on case sensitive files systems, some modules might not load (throwing an error)
  2. on case insensitive file systems, calling require() for the same module but with different case loads the module multiple times (breaking singletons)

@Jeff-Lewis
Copy link

Jeff-Lewis commented May 24, 2016

Please forgive me... I can't believe this actually is how node works on Windows. I just spent several hours debugging to find these issues have been written up for a couple years.

I look at my require.cache and I have hundreds of C:\modules... and hundreds of same c:\modules.... loaded twice.

Please just get someone at MSFT to make a PR....

(edited)
Continuting issue here Repro of Node loading modules twice on Windows

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.