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

On Windows in Node 0.11.13 path.resolve causes files to be re-evaluated on second require #7806

Closed
mgol opened this issue Jun 19, 2014 · 10 comments

Comments

@mgol
Copy link

mgol commented Jun 19, 2014

  1. Install Node 0.11.13 on Windows 8.1
  2. Checkout https://github.com/mzgol/grunt-check-dependencies
  3. Run npm test

Effect: https://ci.appveyor.com/project/mzgol/grunt-check-dependencies/build/3/job/v5ik5b0f0b7nui91

This is because in this line:
https://github.com/mzgol/grunt-check-dependencies/blob/b904397b9ffc459e8a175d0026bd4063eb1f6676/test/spec.js#L37
grunt.config(['checkDependencies', 'ok', 'options']) returns undefined. grunt.config() in this place returns an empty object.

It works fine on OS X (and Linux, as seen in Travis) in both Node 0.10.29 and 0.11.13 and on Windows 8.1 on Node 0.10.29.

I don't currently have a convenient Windows setup to try to narrow the issue down but it seems there's a bug in this specific configuration.

Reported originally as gruntjs/grunt#1166

@indutny
Copy link
Member

indutny commented Jun 19, 2014

Thanks for reporting, but I couldn't accept this as a test case. Could you please reduce it to a chunk of javascript code that doesn't have any external dependencies?

@mgol
Copy link
Author

mgol commented Jun 20, 2014

I managed to set up a Windows VM with Node 0.11.13 and reproduce the issue there. What happens is the node_modules/grunt/lib/grunt/config.js file is evaluated twice in the failing case. I'll try to narrow it further down.

@mgol
Copy link
Author

mgol commented Jun 20, 2014

I have a test case. It consists of 3 files, all in the same directory. In Windows on Git Bash or on OS X if you invoke:

node -e "require('./main')"

you'll get:

file2 required
file1 required

whereas on Windows cmd you'll get:

file2 required
file1 required
file2 required

Files:

  1. main.js:
var path = require('path');
require('./file2.js');
require(path.resolve('./file1.js'));
//require('./file1.js');
  1. file1.js:
console.log('file1 required');
require('./file2.js');
  1. file2.js:
console.log('file2 required');

Interestingly enough, if you uncomment the last line in main.js and comment out the last but one, it starts behaving correctly. It seems that using path.resolve messes it up.

@mgol mgol changed the title On Windows with Node 0.11.13 grunt.config returns an empty object On Windows in Node 0.11.13 path.resolve causes files to be re-evaluated on second require Jun 20, 2014
@mgol
Copy link
Author

mgol commented Jun 20, 2014

The problem seems to boil down to require.resolve using lowercase drive letters and path.resolve using uppercase ones. In Node 0.10 require('./file') resolves the drive letter to uppercase C so they match; it's been changed in 0.11 apparently which causes cache mismatches and modules are loaded again.

@mgol
Copy link
Author

mgol commented Jun 20, 2014

@mgol
Copy link
Author

mgol commented Jun 20, 2014

I wanted to narrow it down further and try to fix it myself but the Module constructor defined in file lib/module.js doesn't seem to be available to the outside so I can't effectively monkey-patch its methods in runtime and building Node on Windows isn't so straigtforward...

So I guess I'll leave you there.

@mgol
Copy link
Author

mgol commented Jul 3, 2014

@indutny Do you need anything else from me?

@indutny
Copy link
Member

indutny commented Jul 31, 2014

cc @orangemocha @piscisaureus

@orangemocha
Copy link
Contributor

There's already a (rather old) PR to address this #6774

@orangemocha
Copy link
Contributor

Fixed in f6e5740

piscisaureus added a commit to piscisaureus/node that referenced this issue Dec 23, 2014
In general path functions don't change the case of a path. Making an
exception for windows drive letters violates the principle of least
surprise.

Changing the drive letter case has caused a lot of issues, including
nodejs#7031, nodejs#7806 and lots of bikeshedding about
whether uppercase is the right case or lowercase.

This effectively reverts nodejs/node-v0.x-archive@a05f973

PR-URL: nodejs/node#100
misterdjules pushed a commit to misterdjules/node that referenced this issue Jan 15, 2015
In general path functions don't change the case of a path. Making an
exception for windows drive letters violates the principle of least
surprise.

Changing the drive letter case has caused a lot of issues, including
nodejs#7031, nodejs#7806 and lots of bikeshedding about
whether uppercase is the right case or lowercase.

This effectively reverts nodejs/node-v0.x-archive@a05f973

PR-URL: nodejs/node#100
misterdjules pushed a commit to misterdjules/node that referenced this issue Jan 15, 2015
In general path functions don't change the case of a path. Making an
exception for windows drive letters violates the principle of least
surprise.

Changing the drive letter case has caused a lot of issues, including
nodejs#7031, nodejs#7806 and lots of bikeshedding about
whether uppercase is the right case or lowercase.

This effectively reverts nodejs/node-v0.x-archive@a05f973

Reviewed-by: Alexis Campailla <alexis@janeasystems.com>
Reviewed-by: Julien Gilli <julien.gilli@joyent.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants