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

Wrong app root path on Windows with scoped packages and nvm #20

Closed
goloroden opened this issue Mar 3, 2017 · 8 comments
Closed

Wrong app root path on Windows with scoped packages and nvm #20

goloroden opened this issue Mar 3, 2017 · 8 comments

Comments

@goloroden
Copy link

I have globally installed a Node.js application on Windows, where Node.js was installed using nvm-windows. This works.

What's unusual about my scenario is that the module is a scoped one, i.e. there is an @org prefix in its name, which results in an additional directory. So the path looks like this:

C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0\node_modules\@org\my-app

This is the application's root path. Now inside of this application I am using a module. It gets installed to the application's node_modules directory, so we end up with:

C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0\node_modules\@org\my-app\node_modules/my-module

Now, this module uses app-root-path to get the root path of the application.

The expected result is:

C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0\node_modules\@org\my-app

The actual result is:

C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0

Obviously app-root-path detects the root path in a wrong way, but I am not sure why. It may be that it is because of the additional node_modules directory (which, I guess, is caused by nvm on Windows), or it may be because the application is a scoped packages.

Unfortunately, as I am not really sure about the cause, I can not provide a fix. Any ideas on this?

@inxilpro
Copy link
Owner

inxilpro commented Mar 3, 2017

Can you post what require('module').globalPaths contains in your app?

@goloroden
Copy link
Author

I'll hand it over to a colleague whom I asked this for.

@FrankStraif
Copy link

Hi,

require('module').globalPath contains:

[ 'C:\\Users\\jane.doe\\.node_modules', 'C:\\Users\\jane.doe\\.node_libraries', 'C:\\Program Files\\lib\\node' ]

Regards,
Frank

@inxilpro
Copy link
Owner

inxilpro commented Mar 6, 2017

Thanks, Frank. I'm not entirely sure how nvm handle setting its module path on Windows. It's odd that C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0\node_modules isn't in that list. What about your NODE_PATH environmental variable? What is that set to?

@FrankStraif
Copy link

Hi Chris,
I have not set NODE_PATH (never needed it).
But even setting NODE_PATH to e.g. "C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0" did not change the behavior, expect that require('module').globalPath now returns

[ '"C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0"',
'C:\Users\jane.doe\.node_modules',
'C:\Users\jane.doe\.node_libraries',
'C:\Program Files\lib\node' ]

appRootPath.path is still set to "C:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0".


Remember: the module is globally installed:
I now debugged a little bit and in resolve.js line 49 the following happens:

  1. resolved is set to:

c:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0\node_modules\@org\my-app\node_modules\app-root-path

  1. the code does:
var nodeModulesDir = sep + 'node_modules';

if (!alternateMethod && -1 !== resolved.indexOf(nodeModulesDir)) {
	var parts = resolved.split(nodeModulesDir);
	if (parts.length) {
		appRootPath = parts[0];
		parts = null;
	}
}
  1. This is how the parts then look like:
parts:
0:"c:\Users\jane.doe\AppData\Roaming\nvm\v6.7.0"
1:"\@org\my-app"
2:"\app-root-path"
  1. and parts[0] is what is finally returned as appRootPath.path.

Hope this helps.

Thanks,
Frank

@navossoc
Copy link

navossoc commented Mar 21, 2017

I have the exactly the same problem (equivalent paths also), but I'm not using nvm or scoped packages.

I'm not sure, but maybe this isn't related to the new "npm flat design packages"?
I'm not a "node expert", so I'm just trying to guess here...

@goloroden
Copy link
Author

Any update on this?

@seognil seognil mentioned this issue Jul 3, 2019
@beanilsson
Copy link

Still experiencing this. Any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants