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

Module.globalPaths under Windows #6434

Closed
qfox opened this issue Apr 27, 2016 · 9 comments
Closed

Module.globalPaths under Windows #6434

qfox opened this issue Apr 27, 2016 · 9 comments
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform.

Comments

@qfox
Copy link

qfox commented Apr 27, 2016

  • Version: 4.3—6.0
  • Platform: Windows 32, 64

Looks like code at https://github.com/nodejs/node/blob/master/lib/module.js#L590:

var paths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];

is Unix specific and since nodejs is installed as c:\program files\nodejs\node.exe the base path resolved to 'C:\\Program Files\\lib\\node', and it's pointless.

Guess this should be fixed to path.resolve(process.env.AppData, 'npm', 'node_modules') for windows, or something similar since right there node_modules are placed by default in win7+.

@mscdex mscdex added module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform. feature request Issues that request new features to be added to Node.js. labels Apr 28, 2016
@jasnell
Copy link
Member

jasnell commented May 17, 2016

@nodejs/ctc @orangemocha ... thoughts on this one?

@mscdex
Copy link
Contributor

mscdex commented May 17, 2016

/cc @nodejs/platform-windows

@qfox
Copy link
Author

qfox commented May 17, 2016

It's definitely not a feature request since atm it does not allow to require globally installed modules because of this bug.

node -p "require('npm');" // Cannot find module
npm i -g anything
node -p "require('anything');" // Still cannot find module

@orangemocha
Copy link
Contributor

AFAIK requiring a module installed with npm install -g some-module is not supposed to work.

From https://docs.npmjs.com/files/folders:

  • Install it locally if you're going to require() it.
  • Install it globally if you're going to run it on the command line.
  • If you need both, then install it in both places, or use npm link.

Agreed that that code is Unix-specific. From https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders:

Additionally, Node.js will search in the following locations:
1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node

None of those paths make sense on Windows, and the use of process.env.USERPROFILE on Windows is undocumented. I think we should fix _initPaths to only support NODE_PATH on Windows, and update the documentation accordingly.

@jasnell
Copy link
Member

jasnell commented May 17, 2016

I think we should fix _initPaths to only support NODE_PATH on Windows, and update the documentation accordingly.

SGTM

@jasongin
Copy link
Member

Don't overlook the line in the documentation immediately following the listing of search locations:

Additionally, Node.js will search in the following locations:
1: $HOME/.node_modules
2: $HOME/.node_libraries
3: $PREFIX/lib/node
Where $HOME is the user's home directory, and $PREFIX is Node.js's configured node_prefix.

I think many Windows users would reasonably interpret "the user's home directory" to be %USERPROFILE% on Windows. So dropping support for loading modules from 1 and 2 above could be considered a breaking change. (And that may be fine, since all these ways of finding modules are essentially deprecated anyway. But it should be deliberate.)

I agree that the 3rd location based on $PREFIX doesn't make sense on Windows.

@nicksoph
Copy link

nicksoph commented Dec 1, 2016

Ran into this whilst trying to setup working files which are held locally on several machines and synced via the cloud which makes global installs problematic. It seems sensible that a configuration file be held at a fixed location in relation to the install but that initial configuration file should be capable of pointing to a second configuration file where all other file paths may be referenced so as to allow the configuration of different machines to point to the same data. This would allow for a separation of what is synced (and is the same) and what is not (which may be different).

@Trott
Copy link
Member

Trott commented Jul 15, 2017

Should this remain open? If so, is it a documentation issue or more than that?

@richardlau
Copy link
Member

#9283 fixed the global paths folder on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Issues that request new features to be added to Node.js. module Issues and PRs related to the module subsystem. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

8 participants