-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Repro of Node loading modules twice on Windows #6978
Comments
I'll revive nodejs/node-v0.x-archive#6774, which I think is an appropriate fix for this issue. |
Module cache lookups should be case-insensitive on Windows, or invoking require() with different casings will end up loading multiple instances of a module. Fixes: nodejs#6978
I'm having this issue as well and is specially annoying using front end libs because you load two of them (React, for example) and everything blows up |
Awesome @orangemocha. Is more needed for a PR? |
I am investigating a unit test failure with those changes. It should be ready shortly. |
Hi @orangemocha. How is the testing going? This issue bit be again in another project today. |
I think I have all the pieces of the puzzle now:
I think the cache key normalization change can be made regardless of the __filename drive normalization, but I wanted to make sure I understood the whole picture. I am on vacation now and unfortunately I didn't have enough time to open the PR and defend it before leaving. I am going to resume this as soon as I get back on July 1st. |
ref #7175 for another discussion on changes to |
I just had my issues with this: I'm connecting mongoose in one place, only to have it disconnected in another. Tracking this down took a lot of time too. Let's just hope you guys can solve this soon.
Tried to confirm my hypothesis, no luck. |
The real cause of this regression is documented at #7726 |
This reverts parts of nodejs@b488b19 restoring javascript implementation of realpath and realpathSync. Fixes: nodejs#7175 Fixes: nodejs#6861 Fixes: nodejs#7294 Fixes: nodejs#7192 Fixes: nodejs#7044 Fixes: nodejs#6624 Fixes: nodejs#6978
Branching issue #6624
Node loading a module twice on Windows
Problem:
Nodejs modules can be loaded twice on Windows due to a change in the drive letter casing.
Using only relative paths, this repo shows how the drive letter can change using
require()
.Uppercase
require.resolve('./moduleA') C:\temp\node_6624\moduleA.js
changes to
Lowercase
require.resolve('./../moduleA') c:\temp\node_6624\moduleA.js
Demonstration of how node modules can be loaded twice on Windows under the following circumstances:
C:\server.js
a child module (in this example moduleB) must be require()'ed with lowercase drive letter, ex.
require(path.join('dir','moduleB'))
A dirty diagram...
C:\moduleA -> c:\moduleB -> c:\moduleA
To Reproduce:
run.bat
You will see at the end of the console output,
moduleA.js
was loaded twice.See test.js for code
How often does this happen?
Why should this be fixed?
The case of the drive letter on Windows should not affect the node run-time and how modules are loaded. _Once this case occurs, all require() paths will be changed causing node to potentially load ALL subsequent modules again._
References:
#6624
#6624 (comment)
The text was updated successfully, but these errors were encountered: