bchatard / alfred-jetbrains

Alfred5 workflow to easily open your projects with your favorite JetBrains product.
MIT License
625 stars 49 forks source link

Unable to launch "idea" #48

Closed shahdewang closed 5 years ago

shahdewang commented 5 years ago

Describe the bug When attempting to open a project using the plugin, I receive "Command failed: /bin/sh -c which idea". I tried to uninstall the module, however, I got an error when doing so.


➜  ~ $ npm uninstall -g @bchatard/alfred-jetbrains

> @bchatard/alfred-jetbrains@1.0.10 preuninstall /usr/local/lib/node_modules/@bchatard/alfred-jetbrains
> alfy-cleanup

Error: Command failed: alfred-unlink
internal/modules/cjs/loader.js:628
    throw err;
    ^

Error: Cannot find module '.'
Require stack:
- /usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)
    at Function.Module._load (internal/modules/cjs/loader.js:527:27)
    at Module.require (internal/modules/cjs/loader.js:683:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink:3:20)
    at Module._compile (internal/modules/cjs/loader.js:777:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)
    at Module.load (internal/modules/cjs/loader.js:643:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:840:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink'
  ]
}

    at makeError (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:174:9)
    at /usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:278:16
    at processTicksAndRejections (internal/process/task_queues.js:85:5) {
  code: 1,
  stdout: '',
  stderr: 'internal/modules/cjs/loader.js:628\n' +
    '    throw err;\n' +
    '    ^\n' +
    '\n' +
    "Error: Cannot find module '.'\n" +
    'Require stack:\n' +
    '- /usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink\n' +
    '    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15)\n' +
    '    at Function.Module._load (internal/modules/cjs/loader.js:527:27)\n' +
    '    at Module.require (internal/modules/cjs/loader.js:683:19)\n' +
    '    at require (internal/modules/cjs/helpers.js:16:16)\n' +
    '    at Object.<anonymous> (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink:3:20)\n' +
    '    at Module._compile (internal/modules/cjs/loader.js:777:30)\n' +
    '    at Object.Module._extensions..js (internal/modules/cjs/loader.js:788:10)\n' +
    '    at Module.load (internal/modules/cjs/loader.js:643:32)\n' +
    '    at Function.Module._load (internal/modules/cjs/loader.js:556:12)\n' +
    '    at Function.Module.runMain (internal/modules/cjs/loader.js:840:10) {\n' +
    "  code: 'MODULE_NOT_FOUND',\n" +
    '  requireStack: [\n' +
    "    '/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/.bin/alfred-unlink'\n" +
    '  ]\n' +
    '}\n',
  failed: true,
  signal: null,
  cmd: 'alfred-unlink',
  timedOut: false,
  killed: false
}

To Reproduce Steps to reproduce the behavior:

  1. launch alfred, type idea, I see the error "Command failed: /bin/sh -c which idea"

Expected behavior On launching alfred and entering idea, it should show a list of projects.

Screenshots If applicable, add screenshots to help explain your problem.

Q A
Workflow version 1.0.10
OSX Version 10.14.6
Alfred Version 4.0.3
JetBrains Product/Version IntelliJ Idea / 2019.2
Installation type JB Toolbox
Node version 12.7.0
NPM version 6.10.0

Additional context The attached screenshot shows an error when attempting to launch workflow from alfred workflow. error

bchatard commented 5 years ago

@shahdewang

Did you use nvm (or similar tools)? Can you provide the content of /usr/local/lib/node_modules/@bchatard/alfred-jetbrains (ls -hAl /usr/local/lib/node_modules/@bchatard/alfred-jetbrains)?

shahdewang commented 5 years ago

No, I do not use nvm or other similar tool.

➜  ~ $ ls -hAl /usr/local/lib/node_modules/@bchatard/alfred-jetbrains
total 232
-rw-r--r--@   1 devangs  admin   186B Oct 26  1985 .editorconfig
drwxr-xr-x@   3 devangs  admin    96B May  3 13:17 .github
-rw-r--r--@   1 devangs  admin    11B Oct 26  1985 .prettierignore
-rw-r--r--@   1 devangs  admin   1.1K Oct 26  1985 LICENSE
-rwxr-xr-x@   1 devangs  admin   3.5K Oct 26  1985 README.md
drwxr-xr-x@   4 devangs  admin   128B May  3 13:17 doc
-rw-r--r--@   1 devangs  admin    63K Oct 26  1985 icon.png
-rw-r--r--@   1 devangs  admin    29K Aug  5 10:40 info.plist
drwxr-xr-x@ 174 devangs  admin   5.4K May  3 13:17 node_modules
-rw-r--r--@   1 devangs  admin   2.1K May  3 13:17 package.json
drwxr-xr-x@   9 devangs  admin   288B May  3 13:17 src
zaherg commented 5 years ago

just a small note, I think adding a double quotation to the command /bin/sh -c "which phpstorm" might fix the issue. as running the command without them will fail.

you can try it on the terminal, mine is zsh + ohmyzsh.

Everything used to work before but not sure why this happened recently. I noticed it after the security update which Apple has released recently btw.

shahdewang commented 5 years ago

Agree, it worked fine for a while. Not sure what broke the change. My env is zsh + ohmyzsh. Do you mind specifying where do I need to make the change?

zaherg commented 5 years ago

I didn't edit anything to be honest, I just tried the command from my terminal, but I guess this line should be changed https://github.com/bchatard/alfred-jetbrains/blob/7dcf234963d094c287b23bd6bb33d6c31afb2c59/src/product.js#L82 from

execa.shellSync(`which ${bin}`)

to

execa.shellSync(`"which ${bin}"`)

again, I didn't test it, and I might be wrong but I thought to share my 2cent here.

shahdewang commented 5 years ago

Did not work, I get a different error

Error: Command failed: /bin/sh -c "which idea"
/bin/sh: which idea: command not found
    at makeError (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:174:9)
    at module.exports.sync (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:338:15)
    at handleShell (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:117:9)
    at Function.module.exports.shellSync (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/node_modules/execa/index.js:361:43)
    at getApplicationPath (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/src/product.js:82:24)
    at Object.get (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/src/product.js:118:31)
    at Object.<anonymous> (/usr/local/lib/node_modules/@bchatard/alfred-jetbrains/src/index.js:7:38)
zaherg commented 5 years ago

Can you try to execute the following commands from the terminal and provide the results

which idea

and

/bin/sh -c "which idea"

Also, have you installed the application via the toolbox or as a standalone?

If you are using the standalone version, have you update it recently? If so, did you recreate the binary or not? as from past experience, if you are using the standalone and you upgraded it, you will need to recreate the CLI again.

shahdewang commented 5 years ago

From command line which idea works fine.

➜  alfred-jetbrains $ /bin/sh -c "which idea"
/usr/local/bin/idea
➜  alfred-jetbrains $ which idea
/usr/local/bin/idea
➜  alfred-jetbrains $

I am using toolbox to manage my applications. Recently upgraded to IntelliJ 2019.2

zaherg commented 5 years ago

sorry man, no idea. hopefully, Brice will find a solution for it soon.

bchatard commented 5 years ago

@linuxjuggler thanks for your help :)

bchatard commented 5 years ago

@shahdewang can you try this repo: https://github.com/bchatard/issue_48 and let me know the result of the script?

zaherg commented 5 years ago

@bchatard this is the result from my end

{ stdout: '/Users/zaher/bin/phpstorm',
  stderr: '',
  code: 0,
  failed: false,
  signal: null,
  cmd: '/bin/sh -c which phpstorm',
  timedOut: false }

but I do have the same issue when I try to use the command via alfred4, it used to work.

My env:

  1. nvm 0.34.0
  2. node v11.15.0
  3. npm 6.10.2
  4. macOs 10.14.6
bchatard commented 5 years ago

@linuxjuggler ok simple script works well. which version of the workflow did you use?

zaherg commented 5 years ago

Should be 1.0.12

Screen Shot 2019-08-06 at 12 44 13 PM

shahdewang commented 5 years ago

I checked out and installed the issue_48 repo, and here's my output (changed phpstorm to idea) -

➜  issue_48 git:(master) ✗ $ node index.js
{
  stdout: '/usr/local/bin/idea',
  stderr: '',
  code: 0,
  failed: false,
  signal: null,
  cmd: '/bin/sh -c which idea',
  timedOut: false
}
bchatard commented 5 years ago

ok thanks.

Actually no idea to workaround this issue :(

Maybe related to issue with Alfred4

Can you try to remove the workflow completely? As you have an issue with Alfred4 you to do some manual task:

  1. In Alfred, delete workflow
  2. Via your terminal, go to this folder: /usr/local/lib/node_modules/@bchatard/alfred-jetbrains
  3. Edit package.json, and remove the following part:
    - "preuninstall": "alfy-cleanup",
  4. Uninstall my workflow: npm uninstall -g @bchatard/alfred-jetbrains
  5. Try to use attached workflow

issue_48.zip

shahdewang commented 5 years ago

I followed the steps, had some issues when uninstalling alfred-jetbrains. I unzipped the attached workflow and installed it. However, still get an error -

Error: Command failed: /bin/sh -c which idea
internal/modules/cjs/loader.js:628
    throw err;
    ^
Error: Cannot find module '../'
Require stack:
- /Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/.bin/which
    at Object.<anonymous> (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/.bin/which:2:13)
    at Function.Module.runMain (internal/modules/cjs/loader.js:840:10) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/.bin/which'
  ]
}
    at makeError (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/execa/index.js:174:9)
    at module.exports.sync (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/execa/index.js:338:15)
    at handleShell (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/execa/index.js:117:9)
    at Function.module.exports.shellSync (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/execa/index.js:361:43)
    at getApplicationPath (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/src/product.js:82:24)
    at Object.get (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/src/product.js:118:31)
    at Object.<anonymous> (/Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/src/index.js:15:38)
bchatard commented 5 years ago

ok, I start to understand something (yes I'm slow :D)

Can you list content of this folder:

ls -hAl /Users/devangs/Dropbox/Alfred/Alfred.alfredpreferences/workflows/user.workflow.32F68A08-AC8E-4C21-9DA0-72DF35D309D7/node_modules/which/*
zaherg commented 5 years ago

@bchatard I don't think the directory you are referring to is something we will have on our end,

for example this is what I have:

total 0
lrwxr-xr-x   1 zaher  staff    84 Jun 18 17:04 @bchatard-alfred-jetbrains -> /Users/zaher/.nvm/versions/node/v11.15.0/lib/node_modules/@bchatard/alfred-jetbrains
lrwxr-xr-x   1 zaher  staff    74 Jun 18 17:06 alfred-packagist -> /Users/zaher/.nvm/versions/node/v11.15.0/lib/node_modules/alfred-packagist
lrwxr-xr-x   1 zaher  staff    72 Jun 18 17:04 alfred-updater -> /Users/zaher/.nvm/versions/node/v11.15.0/lib/node_modules/alfred-updater
drwxr-xr-x@ 23 zaher  staff   736 Aug  8 11:32 user.workflow.0467e292-c285-4b0b-a225-65b12778cf48
drwxr-xr-x@ 10 zaher  staff   320 Aug  8 11:30 user.workflow.0976030A-2D20-407A-A92D-B96B4EFE740C
drwxr-xr-x@ 37 zaher  staff  1184 Jul  3 16:54 user.workflow.1194994C-92D8-420A-90F1-9034BF789D04
drwxr-xr-x@ 25 zaher  staff   800 Aug  8 11:37 user.workflow.1a619a94-9408-45d4-a850-0f5f4807bd18
drwxr-xr-x@  5 zaher  staff   160 Aug  8 11:37 user.workflow.255623E4-1624-4718-A6FF-B53195206B7E
drwxr-xr-x@  8 zaher  staff   256 Aug  8 11:29 user.workflow.2D9C22F9-B900-412F-97F7-E6320D133721
drwxr-xr-x@  8 zaher  staff   256 Aug  8 11:30 user.workflow.2FD73730-B0F4-4FE2-BC3F-F7A5DE01B1E0
drwxr-xr-x@  6 zaher  staff   192 Aug  8 11:37 user.workflow.3A0762FE-0289-4DB7-920F-AE7EAB4C5568
drwxr-xr-x@ 12 zaher  staff   384 Aug  8 11:30 user.workflow.3A231592-35FA-42A1-827B-83F23CD8C9F0
drwxr-xr-x@  5 zaher  staff   160 Jun 14 01:41 user.workflow.3BF3A265-6E14-427F-997A-401BE6FD3110
drwxr-xr-x@  5 zaher  staff   160 Jun 14 01:40 user.workflow.3C59C8D5-9B21-4538-A9AF-D84AA230503A
drwxr-xr-x@  6 zaher  staff   192 Jun 18 17:11 user.workflow.449230D0-7EC2-40E1-BECC-26D2CE020D6C
drwxr-xr-x@  6 zaher  staff   192 Aug  8 11:37 user.workflow.44CCAA7E-F0D4-4B63-B806-C3177A8B8AFE
drwxr-xr-x@  5 zaher  staff   160 Jun 14 01:40 user.workflow.4C51FE61-BC85-4911-B3BF-6EA001F28E65
drwxr-xr-x@ 18 zaher  staff   576 Aug  8 11:33 user.workflow.4ca8872a-cd6b-458d-8e11-96188ec46e50
drwxr-xr-x@  4 zaher  staff   128 Jun 14 01:40 user.workflow.5E136A34-FED0-4FA1-994D-B3C860E355C4
drwxr-xr-x@ 16 zaher  staff   512 Aug  8 11:29 user.workflow.5e7e2d9a-d184-412e-b929-c53c733d9adb
drwxr-xr-x@ 12 zaher  staff   384 Aug  8 11:30 user.workflow.6353414D-8B40-4383-BA94-DE92F0CC14C5
drwxr-xr-x@ 10 zaher  staff   320 Aug  8 11:30 user.workflow.6416E6BB-CE8F-4FEC-BB31-A10297895B58
drwxr-xr-x@  7 zaher  staff   224 Aug  8 11:29 user.workflow.734F5FB3-1009-4725-878B-F9164DC1178D
drwxr-xr-x@ 12 zaher  staff   384 Aug  8 11:30 user.workflow.78ED8829-B662-4563-AC29-9BE8B0ECC10A
drwxr-xr-x@  6 zaher  staff   192 Aug  8 11:37 user.workflow.7ca518b9-f498-4d78-99d8-9f6b263a3bc2
drwxr-xr-x@ 13 zaher  staff   416 Aug  8 11:37 user.workflow.9e8e4a31-556d-4e68-b0c4-47777d4d8c4e
drwxr-xr-x@ 11 zaher  staff   352 Aug  8 11:32 user.workflow.B85F1FFA-1FF5-4AB6-BA83-5B95305B3726
drwxr-xr-x@  9 zaher  staff   288 Aug  8 11:30 user.workflow.C6D04086-E71C-4867-BF07-AE4B81F2402C
drwxr-xr-x@  6 zaher  staff   192 Aug  8 11:30 user.workflow.D114B08F-F425-402F-8487-C22039594B14
drwxr-xr-x@ 14 zaher  staff   448 Aug  8 11:34 user.workflow.E024A028-5DBF-4026-99D8-AB633EFBFF84
drwxr-xr-x@  5 zaher  staff   160 Aug  8 11:37 user.workflow.E32876C0-0E43-474F-BDB5-B22FC0EA860F
drwxr-xr-x@  5 zaher  staff   160 Aug  8 11:29 user.workflow.E38FE728-8BE2-454E-AE00-BC1653C71641
drwxr-xr-x@ 14 zaher  staff   448 Aug  8 11:29 user.workflow.E768CAF7-3B2B-40E3-9895-658A54570203
drwxr-xr-x@  6 zaher  staff   192 Aug  8 11:37 user.workflow.EA56D641-A421-4BBB-9935-4FCB282ADDA3
drwxr-xr-x@ 25 zaher  staff   800 Aug  8 11:37 user.workflow.a91d754c-4803-4009-ad74-5ce311f358be
drwxr-xr-x@  9 zaher  staff   288 Aug  8 11:29 user.workflow.aa13b89e-de50-423c-8147-95a35e923fe2

so you might need to provide us more info so we can help you more

bchatard commented 5 years ago

@linuxjuggler this folder is based on answer from @shahdewang with "manual" workflow installation.

In your case (as "normal" installation) it's: /.../Alfred.alfredpreferences/workflows/@bchatard-alfred-jetbrains/node_modules/which/*

zaherg commented 5 years ago

Ok :

➜  @bchatard-alfred-jetbrains git:(3d9c31d) ✗ ls -hAl node_modules/which/*
-rw-r--r--@ 1 zaher  staff   2.4K Oct 26  1985 node_modules/which/CHANGELOG.md
-rw-r--r--@ 1 zaher  staff   765B Oct 26  1985 node_modules/which/LICENSE
-rw-r--r--@ 1 zaher  staff   1.2K Oct 26  1985 node_modules/which/README.md
-rw-r--r--@ 1 zaher  staff   1.9K Jun 18 17:04 node_modules/which/package.json
-rw-r--r--@ 1 zaher  staff   3.1K Oct 26  1985 node_modules/which/which.js

node_modules/which/bin:
total 8
-rwxr-xr-x@ 1 zaher  staff   985B Oct 26  1985 which

"Removed the un-usefull and confusing comment I added"

bchatard commented 5 years ago

O_o the package.json is not mine the homepage field is not correct, there is no @vue/cli or typescript dependencies it's really weird and there is no git in this folder when you install package with npm it's really really weird

can you try a fresh install?

zaherg commented 5 years ago

I'll do so and let you know the results.

I just noticed that this is related to nvm, so I you can forget my comment about the modification

zaherg commented 5 years ago

Sorry @bchatard for the confusion I did, but now that I deleted the npm package completely (to be honest I used rm instead of npm, am not sure why but I got this error when I tried to list the global packages

npm ERR! error in /Users/zaher/.nvm/versions/node/v11.15.0/lib/node_modules/@bchatard/.DS_Store: ENOTDIR: not a directory, open '/Users/zaher/.nvm/versions/node/v11.15.0/lib/node_modules/@bchatard/.DS_Store/package.json'

so I delete the directory completely, and then reinstalled the package again npm install -g @bchatard/alfred-jetbrains

and now its back working as it should

Screen_Shot_2019-08-09_at_10_26_53_AM

and here is the result of the command:

alfred-jetbrains git:(3d9c31d) ✗ ls -hAl node_modules/which/*
-rw-r--r--@ 1 zaher  staff   2.4K Oct 26  1985 node_modules/which/CHANGELOG.md
-rw-r--r--@ 1 zaher  staff   765B Oct 26  1985 node_modules/which/LICENSE
-rw-r--r--@ 1 zaher  staff   1.2K Oct 26  1985 node_modules/which/README.md
-rw-r--r--  1 zaher  staff   1.9K Aug  9 10:22 node_modules/which/package.json
-rw-r--r--@ 1 zaher  staff   3.1K Oct 26  1985 node_modules/which/which.js

node_modules/which/bin:
total 8
-rwxr-xr-x  1 zaher  staff   985B Oct 26  1985 which

which, as you can see, is the same as the above (except the package.json modification date which is related to the installation date).

Not sure why, but deleting the package and reinstall it fixed the issue at my end.

shahdewang commented 5 years ago

Reinstall worked for me. Yay!!