-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
relative module paths resolve differently in REPL. #5684
Comments
@jdalton thanks for the report! Operating system? Locally - On 5.1.0 I see: $ node
> require("./lodash.js").VERSION
'should be me' Updating to 5.8 I get: $ node
> require("./lodash.js").VERSION
'should be me' So assuming it didn't break between 5.1 and 5.8 I suspect it might be OS related. |
OSX 10.11.3
The issue is |
Oh sorry, my bad. I see |
Cool, so it repros on Windows and OSX. |
require("module")._resolveFilename("./lodash") // returns the value in node_modules Since [ './lodash',
[ 'C:\\issue-5684\\node_modules',
'C:\\node_modules',
'.',
'C:\\Users\\Benjamin\\.node_modules',
'C:\\Users\\Benjamin\\.node_libraries',
'C:\\Program Files (x86)\\lib\\node' ] ] Which finds lodash if I do: var paths = require("module")._resolveLookupPaths("./lodash")
require("module")._findPath("./lodash", paths[1]) // C:\\issue-5684\\node_modules\\lodash\\lodash.js Which happens because of "hacky" code (terminology used) in repl.js. I have to leave now, but I'm at Lines 263 to 264 in 7c60328
. and not above.
I'll keep debugging later - anyone feel free to pick this up. |
to place the node_modules paths below the - var mainPaths = ['.'].concat(modulePaths);
- mainPaths = Module._nodeModulePaths('.').concat(mainPaths);
+ var mainPaths = Module._nodeModulePaths('.').concat(mainPaths);
+ mainPaths = ['.'].concat(modulePaths); |
I think I have a working test... going to see if this fix makes things work |
@thealphanerd anything near what I've done in #5689? |
@phillipj the test is different. There is already a Your test might be good to have as well, but the one I used is running in the repl itself. I'm going to push it to a fork, might make sense for you to cherry pick and add to your PR... I'll post it in there |
This fixes a bug where a 3rd party module found in node_modules, would be preferred over a ./local module with the same name. Fixes: nodejs#5684 PR-URL: nodejs#5689 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
npm init # <init a package> npm i lodash --save touch lodash.js
In lodash.js
Now in the REPL
Put the same code in a file
In foo.js
Then
node foo # logs 'should be me'
It would work in the REPL if I changed the path from
'./lodash'
to'./lodash.js'
.The text was updated successfully, but these errors were encountered: