Skip to content

require module cache should do case-insensitive lookups on case-insensitive file systems #30015

@mnaoumov

Description

@mnaoumov
  • Version: v12.12.0 (also tried v10.16.3)
  • Platform: Windows x64
  • Subsystem: module

Windows is using case-insensitive file systems. So essentially myModule.js and MYMODULE.JS are the same files.

Node.JS require is using caching so if you are trying to resolve a module the second time you are getting the same instance of it.

But this cache is case-sensitive so we are getting

require('myModule') === require('myModule');
require('myModule') !== require('MYMODULE');

You may say, that it is by design but I found an important usecase that you should consider.

There are situations when __dirname and process.cwd() are the same but with different cases. So child dependencies would be loaded independently without caching and that can introduce very weird and difficult to identify issues.

I've prepared a demo gist to show the problem

For more details, see my blogpost

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions