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

Does not return the correct absolute path #20

Open
jbouhier opened this issue Nov 3, 2017 · 13 comments
Open

Does not return the correct absolute path #20

jbouhier opened this issue Nov 3, 2017 · 13 comments

Comments

@jbouhier
Copy link

jbouhier commented Nov 3, 2017

Hello @jonschlinkert,

When I use npm-check --global --update, which depends on global-modules and finally global-prefix, I've got an incorrect path error which points to ${HOME}/.npm-packages instead of the actual absolute path.

I've done a little bit of digging inside global-prefix and ${HOME}/.npm-packages seems to be returned from tryConfigPath(configPath). Looks like the value of ${HOME} is not parsed with the actual value.

I'm not sure if I should fix this here or if the cause is coming from some other component (i.e: npm-check, node or npm version...).

Here's my config:

  • Node 8.9.0
  • Npm 5.5.1

Let me know if I can do a PR to fix it 😃

@jonschlinkert
Copy link
Owner

Let me know if I can do a PR to fix it

That would be great, but first, let's get more info about your setup. What OS/version are you on? etc.

@jbouhier
Copy link
Author

jbouhier commented Nov 3, 2017

I'm on macOS Sierra 10.12.6. I already told you about the Node and npm version I'm using. The package npm-check which prompted the error is installed globally on my system.

I think I should take a look at the code of the ini package.
What else can do you need to know ?

@jonschlinkert
Copy link
Owner

hmm, that answered my main question. I think your suggestion about looking into ini is good, since it seems to be a bug in a module that provides path information to this lib.

Was there any more information in the error message you could share? can you get a stack trace?

@jbouhier
Copy link
Author

jbouhier commented Nov 3, 2017

Of course. It's definitely coming from ini module. I'll dig into the bug this weekend. Should I open an issue on that other repo and ask guidance to the maintainers ? It's my first time trying to contribute to OSS.

➜ npm-check --global --update --debug

[npm-check] debug
cli.flags { update: true,
  u: true,
  global: true,
  g: true,
  skipUnused: false,
  s: false,
  production: false,
  p: false,
  devOnly: false,
  d: false,
  saveExact: false,
  E: false,
  color: false,
  emoji: true,
  spinner: true,
  debug: true,
  dir: '/Users/synxs' }
===============================
[npm-check] debug
cli.input []
===============================
[npm-check] debug
set key spinner to value true
===============================
[npm-check] debug
set key ignore to value undefined
===============================
Path "/Users/synxs/${HOME}/.npm-packages/lib/node_modules" does not exist. Please check the NODE_PATH environment variable.
   23 |                    modulesPath = process.env.NODE_PATH;
   24 |                }
   25 |            }
   26 |
   27 |            if (!fs.existsSync(modulesPath)) {
 > 28 |                throw new Error('Path "' + modulesPath + '" does not exist. Please check the NODE_PATH environment variable.');
   29 |            }
   30 |
   31 |            console.log(chalk.green('The global path you are searching is: ' + modulesPath));
   32 |
   33 |            currentState.set('cwd', globalModulesPath);

   at Promise (/Users/synxs/.npm-packages/lib/node_modules/npm-check/lib/state/init.js:28:23)
   at init (/Users/synxs/.npm-packages/lib/node_modules/npm-check/lib/state/init.js:12:12)
   at state (/Users/synxs/.npm-packages/lib/node_modules/npm-check/lib/state/state.js:75:12)
   at init (/Users/synxs/.npm-packages/lib/node_modules/npm-check/lib/index.js:7:12)
   at Object.<anonymous> (/Users/synxs/.npm-packages/lib/node_modules/npm-check/lib/cli.js:96:1)
   at Module._compile (module.js:635:30)
   at Object.Module._extensions..js (module.js:646:10)
   at Module.load (module.js:554:32)
   at tryModuleLoad (module.js:497:12)

@doowb
Copy link
Collaborator

doowb commented Nov 3, 2017

@jbouhier that's stack trace is helpful, thanks.

Will you run the following commands from the command line?

node -e "console.log('NODE_PATH:', process.env.NODE_PATH)"
node -e "console.log('HOME:', process.env.HOME)"

I see in the code above that if process.env.NODE_PATH is set then that's used instead of the value from global-modules.

If it's not set, then we can dig deeper by looking at process.env.HOME.

It's my first time trying to contribute to OSS.

😀 maybe we'll track down a bug that you can submit a PR for!

@jbouhier
Copy link
Author

jbouhier commented Nov 3, 2017

Hey @doowb, here's the output:

➜  ~ node -e "console.log('NODE_PATH:', process.env.NODE_PATH)"
NODE_PATH: undefined
➜  ~ node -e "console.log('HOME:', process.env.HOME)"
HOME: /Users/synxs

Before creating this issue, I tried setting NODE_PATH in my shell .rc file and it worked fine.
Nevertheless, the bug is still present and needs to be addressed in my opinion.

In my ~/.npmrc file I have:
prefix = ${HOME}/.npm-packages
${HOME} should be parsed by npm/ini to /current/user/home/path/ as written on npmrc's doc.

I guess I'm on the right track, aren't I ?
If not, what do you suggest I try ?

@doowb
Copy link
Collaborator

doowb commented Nov 3, 2017

It looks like npm is replacing the environment variables after it reads in the config using ini.

I'm not sure if resolving environment variables belongs here or in consuming modules, but it seems similar to how ~ is expanded using expand-tilde in this module, so maybe it belongs here.

Also, does that syntax vary between operating systems?

@jbouhier
Copy link
Author

jbouhier commented Nov 3, 2017

I'll have to get back on you after spinning up a few VMs and try it out.
Will follow up tomorrow.

@jbouhier
Copy link
Author

jbouhier commented Nov 8, 2017

Debian 9 / kernel 4.9.0-4-amd64

  • NodeJS 8.9.1
  • npm-check 5.5.2

Same result exact error and stack trace with npm-check -gu --debug.
The error is thrown inside init.js 28:23 both on Debian and Mac.

Debugging init module now.

@tunnckoCore
Copy link
Contributor

Ha. Is this still a bug? Probably. It sounds my like a source for the tunnckoCore/get-installed-path#79 issue.

@jbouhier
Copy link
Author

jbouhier commented Jun 19, 2018

Hello @olstenlarck,

Yes, it might still be. I just commented out prefix = .npm-packages from my ~/.npmrc file as a workaround to get rid of the error messages.

@jonschlinkert
Copy link
Owner

If this is still a bug, does anyone have a suggested fix or solution I can try? Or a PR?

@jbouhier
Copy link
Author

Haven't tried again. Gonna take a look again.

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

4 participants