-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
Closed
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.
Description
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:
- command line launching initial node module must use uppercase drive letter, ex.
C:\server.js - There must be a circular reference between modules somewhere along the dependency chain where
a child module (in this example moduleB) must be require()'ed with lowercase drive letter, ex.require(path.join('dir','moduleB')) - When moduleB requires moduleA, it will use the lowercase drive letter in it's path.
A dirty diagram...
C:\moduleA -> c:\moduleB -> c:\moduleA
To Reproduce:
- Using Windows, clone this repo
- run
run.bat
You will see at the end of the console output, moduleA.js was loaded twice.
*** require.cache ***
[ 'C:\\temp\\node_6624\\test.js',
'C:\\temp\\node_6624\\moduleA.js',
'c:\\temp\\node_6624\\childFolder\\moduleB.js',
'c:\\temp\\node_6624\\moduleA.js' ]
See test.js for code
How often does this happen?
- WebStorm IDE by default uses uppercase letters in the command line when debugging node.
- Loading modules by way of path.join() is common in many frameworks.
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:
- Version: 4.4
- Platform: Windows 10 64-bit
- Subsystem: none
icebob
Metadata
Metadata
Assignees
Labels
moduleIssues and PRs related to the module subsystem.Issues and PRs related to the module subsystem.windowsIssues and PRs related to the Windows platform.Issues and PRs related to the Windows platform.