Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing with different casing breaks instanceof checks #14084

Closed
ScallyGames opened this issue Jul 5, 2017 · 3 comments
Closed

Importing with different casing breaks instanceof checks #14084

ScallyGames opened this issue Jul 5, 2017 · 3 comments
Labels
module Issues and PRs related to the module subsystem.

Comments

@ScallyGames
Copy link

  • Version: 8.1.3
  • Platform: Windows 10 Pro x64

When importing one file with different casing they are both imported correctly without errors, however they are not equal. Because objects instantiated with one import are not instanceof the other import.

Run following code to see it in action:

// foo.js
function Foo() {}
module.exports = Foo;

// index.js
let Foo = require('./foo');
let Foo2 = require('./Foo'); // Foo.js does not exist, imports foo.js however
let Foo3 = require('./foo');

console.log(Foo);
console.log(Foo2);

console.log('Foo === Foo2: ' + (Foo === Foo2));
console.log('Foo === Foo3: ' + (Foo === Foo3));


console.log('new Foo() instanceof Foo2: ' + (new Foo() instanceof Foo2));
console.log('new Foo2() instanceof Foo: ' + (new Foo2() instanceof Foo));

console.log('new Foo() instanceof Foo: ' + (new Foo() instanceof Foo));
console.log('new Foo2() instanceof Foo2: ' + (new Foo2() instanceof Foo2));

or clone and node index.js this reproduction repositiory.

This is probably related to #7726, #6978 and node-v0.x-archive/pull/6774, however it still exists while the other issues are said to be resolved.

@vsemozhetbyt vsemozhetbyt added the module Issues and PRs related to the module subsystem. label Jul 5, 2017
@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Jul 5, 2017

It seems this may work as intended if I get this right. In case-sensitive OS these would be 2 different modules and Node.js may not distinguish case-sensitiveness of file systems here. See #14019 (comment)

But I may be wrong, let's see what others think.

@tniessen
Copy link
Member

tniessen commented Jul 5, 2017

This is a known problem due to the general case-insensitivity on Windows platforms. From the perspective of our module system, these are different paths, therefore different modules, and we cannot prevent Windows from resolving different paths to the same file.

A solution for this particular problem might be to use the lowercase variant of module paths within our cache, making the keys unique again. However, I remember reading something about Windows being able to deal with some case-sensitive filesystems, see e.g. here, so that behavior would eventually break.

I don't think there is an efficient solution to this problem and agree with @vsemozhetbyt. You can implement relevant checks in JavaScript by overwriting our module loading implementation with one which checks the capitalization, but this won't be as efficient.

@ScallyGames
Copy link
Author

ScallyGames commented Jul 5, 2017

Thanks for the quick answer.
In my case setting --forceConsistentCasingInFileNames in my TypeScript compiler config will probably be enough to keep me from repeating this error.

Your explanation sounds reasonable and if there is general consents that there is nothing to fix feel free to close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module Issues and PRs related to the module subsystem.
Projects
None yet
Development

No branches or pull requests

3 participants