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

Cannot log in when using nvm #50

Closed
sarumont opened this issue May 16, 2017 · 4 comments
Closed

Cannot log in when using nvm #50

sarumont opened this issue May 16, 2017 · 4 comments

Comments

@sarumont
Copy link

sarumont commented May 16, 2017

I'm trying to set up alfred-jira, and I currently cannot log in. I'm attempting to debug via shell rather than through Alfred, and this is what I see:

/Users/richard/src/alfred-jira/lib/jira/auth.js:19
      if (err) throw err;
               ^

Error: Command failed: /bin/zsh -c "eval $(/usr/libexec/path_helper | awk '{print $1}') npm run electron login"
module.js:442
    throw err;
    ^

Error: Cannot find module './'
    at Function.Module._resolveFilename (module.js:440:15)
    at Function.Module._load (module.js:388:25)
    at Module.require (module.js:468:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/Users/richard/src/alfred-jira/node_modules/.bin/electron:3:16)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)

npm ERR! Darwin 16.5.0
npm ERR! argv "/Users/richard/.nvm/versions/node/v6.3.1/bin/node" "/Users/richard/.nvm/versions/node/v6.3.1/bin/npm" "run" "electron" "login"
npm ERR! node v6.3.1
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! alfred-jira@1.0.4 electron: `electron . "login"`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the alfred-jira@1.0.4 electron script 'electron . "login"'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the alfred-jira package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     electron . "login"
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs alfred-jira
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls alfred-jira
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/richard/src/alfred-jira/npm-debug.log

    at ChildProcess.exithandler (child_process.js:202:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:852:16)
    at Socket.<anonymous> (internal/child_process.js:323:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:492:12)

And npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/Users/richard/.nvm/versions/node/v6.3.1/bin/node',
1 verbose cli   '/Users/richard/.nvm/versions/node/v6.3.1/bin/npm',
1 verbose cli   'run',
1 verbose cli   'electron',
1 verbose cli   'login' ]
2 info using npm@3.10.3
3 info using node@v6.3.1
4 verbose run-script [ 'preelectron', 'electron', 'postelectron' ]
5 info lifecycle alfred-jira@1.0.4~preelectron: alfred-jira@1.0.4
6 silly lifecycle alfred-jira@1.0.4~preelectron: no script for preelectron, continuing
7 info lifecycle alfred-jira@1.0.4~electron: alfred-jira@1.0.4
8 verbose lifecycle alfred-jira@1.0.4~electron: unsafe-perm in lifecycle true
9 verbose lifecycle alfred-jira@1.0.4~electron: PATH: /Users/richard/.nvm/versions/node/v6.3.1/lib/node_modules/npm/bin/node-gyp-bin:/Users/richard/src/alfred-jira/node_modules/.bin:/Users/richard/.nvm/versions/node/v6.3.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Users/richard/.nvm/versions/node/v6.3.1/bin:/Users/richard/.sdkman/candidates/maven/current/bin:/Users/richard/.sdkman/candidates/java/current/bin:/Users/richard/.sdkman/candidates/groovy/current/bin:/Users/richard/.sdkman/candidates/gradle/current/bin:/Users/richard/.local/bin:/Users/richard/.dotfiles/bin:/opt/android/platform-tools:/opt/android/tools:/usr/local/heroku/bin:/Users/richard/.rvm/bin:.
10 verbose lifecycle alfred-jira@1.0.4~electron: CWD: /Users/richard/src/alfred-jira
11 silly lifecycle alfred-jira@1.0.4~electron: Args: [ '-c', 'electron . "login"' ]
12 silly lifecycle alfred-jira@1.0.4~electron: Returned: code: 1  signal: null
13 info lifecycle alfred-jira@1.0.4~electron: Failed to exec electron script
14 verbose stack Error: alfred-jira@1.0.4 electron: `electron . "login"`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (/Users/richard/.nvm/versions/node/v6.3.1/lib/node_modules/npm/lib/utils/lifecycle.js:242:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/Users/richard/.nvm/versions/node/v6.3.1/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:852:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid alfred-jira@1.0.4
16 verbose cwd /Users/richard/src/alfred-jira
17 error Darwin 16.5.0
18 error argv "/Users/richard/.nvm/versions/node/v6.3.1/bin/node" "/Users/richard/.nvm/versions/node/v6.3.1/bin/npm" "run" "electron" "login"
19 error node v6.3.1
20 error npm  v3.10.3
21 error code ELIFECYCLE
22 error alfred-jira@1.0.4 electron: `electron . "login"`
22 error Exit status 1
23 error Failed at the alfred-jira@1.0.4 electron script 'electron . "login"'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the alfred-jira package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     electron . "login"
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs alfred-jira
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls alfred-jira
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

I am using nvm to manage node versions, obviously, but I don't see that being a problem here. Any tips / ideas on how to debug this?

@steyep
Copy link
Owner

steyep commented May 16, 2017

You really should debug this within Alfred because it's a different environment from your terminal. One of the main differences being what is available to Alfred on your $PATH at the time of execution. My initial thought is that nvm is the problem.

That said, to better determine what's happening within the Alfred environment, add this to the first line of ./lib/scriptfilter.js:

return console.error(require('./alfred-exec').execSync(`which node; which npm`).toString());

Open Alfred's debugger with the workflow selected and enter the keyword into Alfred. That should tell you:

  • which version of node Alfred is using
  • the path to node Alfred is using
  • the path to npm Alfred is using

Then you can compare that output to the output you get from terminal and nvm and see where the differences are.

While I currently do not, nor do I have future plans to support nvm, I understand that not everyone has node installed at /usr/local/bin/node so I'm wondering if adding a config variable for path/to/node at installation time would be beneficial...

@sarumont
Copy link
Author

sarumont commented May 16, 2017

I started in Alfred's debugger and moved out because it was easier in the terminal. :)

Your comments sent me down a different path than I was going, and I ended up getting it working. For anyone else running into this issue, first update the first step in the workflow to use the full path to your nvm-managed node. Then, apply this patch:

--- a/lib/alfred-exec.js
+++ b/lib/alfred-exec.js
@@ -1,20 +1,21 @@
 const child = require('child_process');
 let shell = process.env.SHELL;
+let home = process.env.HOME;
 let escQuotes = str => str.replace(/"/g,'\\"');
 let escSpace = str => str.replace(/ /g, '\\ ');
-const PATH = `eval $(/usr/libexec/path_helper | awk '{print $1}')`;
+const PATH = `/usr/libexec/path_helper | awk '{print $1}'`;

 module.exports = {
   'exec': (cmd, options, callback) => {
     cmd = escQuotes(cmd);
-    return child.exec(`${shell} -c "${PATH} ${cmd}"`, options, callback);
+    return child.exec(`${shell} -c ". ${home}/.nvm/nvm.sh && ${PATH} && ${cmd}"`, options, callback);
   },
   'execSync': (cmd, options) => {
     cmd = escQuotes(cmd);
-    return child.execSync(`${shell} -c "${PATH} ${cmd}"`, options);
+    return child.execSync(`${shell} -c ". ${home}/.nvm/nvm.sh && ${PATH} && ${cmd}"`, options);
   },
   'spawn': (cmd, args, options) => {
     args = args.map(escSpace)
-    return child.spawn(shell, ['-c', `${PATH} ${cmd} ${args.join(' ')}`], options);
+    return child.spawn(shell, ['-c', `. {home}/.nvm/nvm.sh && ${PATH} && ${cmd} ${args.join(' ')}`], options);
   }
-}

Et voila!

Thanks for the workflow and help, @steyep. Closing this as you (rightly) don't plan to support nvm.

@sarumont sarumont changed the title Cannot log in Cannot log in when using nvm May 16, 2017
@steyep
Copy link
Owner

steyep commented May 17, 2017

Cool, I'm glad you were able to get it working. Don't forget the $ in the spawn command:

return child.spawn(shell, ['-c', `. ${home}/.nvm/nvm.sh && ${PATH} && ${cmd} ${args.join(' ')}`], options);

You might also consider testing for the nvm script before trying to load it – that way the workflow won't break if you uninstall nvm somewhere down the road 😄

const nvm = `test -f ${process.env.HOME}/.nvm/nvm.sh && ${process.env.HOME}/.nvm/nvm.sh`;

module.exports = {
  'exec': (cmd, options, callback) => {
    cmd = escQuotes(cmd);
    return child.exec(`${shell} -c "${nvm}; ${PATH} && ${cmd}"`, options, callback);
  },
  'execSync': (cmd, options) => {
    cmd = escQuotes(cmd);
    return child.execSync(`${shell} -c "${nvm}; ${PATH} && ${cmd}"`, options);
  },
  'spawn': (cmd, args, options) => {
    args = args.map(escSpace)
    return child.spawn(shell, ['-c', `${nvm}; ${PATH} && ${cmd} ${args.join(' ')}`], options);
  }
}

@sarumont
Copy link
Author

Thanks for spotting the $!

As to testing for nvm.sh, I like my hacks as hackish as possible. 8)

Cheers!

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

2 participants