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

Issue with Global Install of Ngrok in Linux With NPM #87

Closed
ghost opened this issue Jul 22, 2017 · 19 comments
Closed

Issue with Global Install of Ngrok in Linux With NPM #87

ghost opened this issue Jul 22, 2017 · 19 comments

Comments

@ghost
Copy link

ghost commented Jul 22, 2017

Issue that arises.

Done with Arch Linux using npm version 5.3.0 with Linux Kernel 4.11.5-1-ARCH

sudo npm i -g ngrok
/usr/bin/ngrok -> /usr/lib/node_modules/ngrok/bin/ngrok

> ngrok@2.2.15 postinstall /usr/lib/node_modules/ngrok
> node ./postinstall.js

ngrok - downloading binary https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
events.js:182
      throw er; // Unhandled 'error' event
      ^

Error: EACCES: permission denied, open '/usr/lib/node_modules/ngrok/ngrok.zip'
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ngrok@2.2.15 postinstall: `node ./postinstall.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ngrok@2.2.15 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2017-07-22T14_30_23_601Z-debug.log

Content from Log File about the error

2136 verbose lifecycle ngrok@2.2.15~postinstall: CWD: /usr/lib/node_modules/ngrok
2137 silly lifecycle ngrok@2.2.15~postinstall: Args: [ '-c', 'node ./postinstall.js' ]
2138 silly lifecycle ngrok@2.2.15~postinstall: Returned: code: 1  signal: null
2139 info lifecycle ngrok@2.2.15~postinstall: Failed to exec postinstall script
2140 verbose unlock done using /root/.npm/_locks/staging-a072192f34a17023.lock for /usr/lib/node_modules/.staging
2141 verbose stack Error: ngrok@2.2.15 postinstall: `node ./postinstall.js`
2141 verbose stack Exit status 1
2141 verbose stack     at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:289:16)
2141 verbose stack     at emitTwo (events.js:125:13)
2141 verbose stack     at EventEmitter.emit (events.js:213:7)
2141 verbose stack     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
2141 verbose stack     at emitTwo (events.js:125:13)
2141 verbose stack     at ChildProcess.emit (events.js:213:7)
2141 verbose stack     at maybeClose (internal/child_process.js:897:16)
2141 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
2142 verbose pkgid ngrok@2.2.15
@bubenshchykov
Copy link
Owner

bubenshchykov commented Jul 22, 2017

thx for reporting!
looks like it's a regression of previous pr
https://github.com/bubenshchykov/ngrok/pull/85/files#diff-551007241ae61889b0f85f47aa764343R106

@gaoqiankun can you quickly spot some permission problems here?

outputStream.write(data); // temp file
fs.createWriteStream(localFile); // or here

I can add .on('error') handlers to prevent uncaught, but I'm not sure what the problem is yet

@ghost
Copy link
Author

ghost commented Jul 22, 2017

Hi,

No problem. I am working on a project right now, but I should be done with it in 3-ish hours. If you want and have not solved it by then, I can take a look and see if I can resolve it and will add a pull request if I do.

@gaoqiankun
Copy link
Contributor

gaoqiankun commented Jul 25, 2017

@TKOBabu
I have tried sudo npm i -g ngrok on archlinux, but i got a lot package not found error
e.g.

vagrant@archlinux:~$ sudo npm i -g ngrok
/usr/bin/ngrok -> /usr/lib/node_modules/ngrok/bin/ngrok

> ngrok@2.2.15 postinstall /usr/lib/node_modules/ngrok
> node ./postinstall.js

module.js:487
    throw err;
    ^

Error: Cannot find module 'hawk'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/request/request.js:9:12)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
npm ERR! Linux 4.11.9-1-ARCH
vagrant@archlinux:~$ sudo npm i -g ngrok
/usr/bin/ngrok -> /usr/lib/node_modules/ngrok/bin/ngrok

> ngrok@2.2.15 postinstall /usr/lib/node_modules/ngrok
> node ./postinstall.js

module.js:487
    throw err;
    ^

Error: Cannot find module 'safe-buffer'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/request/lib/helpers.js:5:14)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
npm ERR! Linux 4.11.9-1-ARCH

Then, i install ngrok on ubuntu by sudo npm i -g ngrok and on cygwin bynpm i -g ngrok, it works fine.

gaoqiankun@dev1:/home/vagrant$ sudo npm i -g ngrok
/usr/bin/ngrok -> /usr/lib/node_modules/ngrok/bin/ngrok

> ngrok@2.2.15 postinstall /usr/lib/node_modules/ngrok
> node ./postinstall.js

ngrok - downloading binary https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
ngrok - downloading progress: 5363700/5363700
ngrok - binary downloaded to /usr/lib/node_modules/ngrok/bin/aHR0cHM6Ly9iaW4uZXF1aW5veC5pby9jLzRWbUR6QTdpYUhiL25ncm9rLXN0YWJsZS1saW51eC1hbWQ2NC56aXA=.zip
ngrok - unpacking binary
ngrok - binary unpacked to /usr/lib/node_modules/ngrok/bin/ngrok
/usr/lib
└── ngrok@2.2.15
Administrator@pgos MINGW64 ~/Desktop
$ npm i -g ngrok
C:\Users\Administrator\AppData\Roaming\npm\ngrok -> C:\Users\Administrator\AppDa                                                                                                                           ta\Roaming\npm\node_modules\ngrok\bin\ngrok

> ngrok@2.2.15 postinstall C:\Users\Administrator\AppData\Roaming\npm\node_modul                                                                                                                           es\ngrok
> node ./postinstall.js

ngrok - downloading binary https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-win                                                                                                                           dows-amd64.zip
ngrok - downloading progress: 5411323/5411323
ngrok - binary downloaded to C:\Users\Administrator\.ngrok\aHR0cHM6Ly9iaW4uZXF1a                                                                                                                           W5veC5pby9jLzRWbUR6QTdpYUhiL25ncm9rLXN0YWJsZS13aW5kb3dzLWFtZDY0LnppcA==.zip
ngrok - unpacking binary
ngrok - binary unpacked to C:\Users\Administrator\AppData\Roaming\npm\node_modul                                                                                                                           es\ngrok\bin\ngrok.exe
C:\Users\Administrator\AppData\Roaming\npm
`-- ngrok@2.2.15

I don't think creating read/write stream will cause permission problem, and I never use archlinux before, can you give me some more time, to find what the real problem is.

@bubenshchykov
Copy link
Owner

@gaoqiankun @TKOBabu thanks for investigation!
I tried global install on mac only, with and without cached bin - both cases worked fine.
can you try to bump npm and install ngrok again npm i npm -g ?

@gaoqiankun
Copy link
Contributor

@bubenshchykov
sudo npm i -g npm works successfuly, but when i run npm --version, it throw error

vagrant@archlinux:~$ sudo npm i -g npm@2
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
+ npm@2.15.12
added 69 packages, removed 278 packages and updated 133 packages in 40.023s
vagrant@archlinux:~$ npm -v
module.js:487
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:485:15)
    at Function.Module._load (module.js:437:25)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at /usr/lib/node_modules/npm/bin/npm-cli.js:18:11
    at Object.<anonymous> (/usr/lib/node_modules/npm/bin/npm-cli.js:75:3)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
vagrant@archlinux:~$

Then i tried sudo npm i -g typescript, it works fine

vagrant@archlinux:~$ sudo npm i -g typescript
/usr/bin/tsc -> /usr/lib/node_modules/typescript/bin/tsc
/usr/bin/tsserver -> /usr/lib/node_modules/typescript/bin/tsserver
typescript@2.4.2 /usr/lib/node_modules/typescript
vagrant@archlinux:~$ ts
ts        tsc       tset      tsort     tsserver
vagrant@archlinux:~$ ts --help
Unknown option: help
usage: ts [-r] [-i | -s] [format]
vagrant@archlinux:~$ tsc --help
Version 2.4.2
Syntax:   tsc [options] [file ...]

Examples: tsc hello.ts
          tsc --outFile file.js file.ts
          tsc @args.txt
...

Then sudo npm i -g node-sass, and i got permission error

vagrant@archlinux:~$ sudo npm i -g node-sass
/usr/bin/node-sass -> /usr/lib/node_modules/node-sass/bin/node-sass

> node-sass@4.5.3 install /usr/lib/node_modules/node-sass
> node scripts/install.js

fs.js:652
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: EACCES: permission denied, open '/usr/lib/node_modules/node-sass/package.json'
    at Object.fs.openSync (fs.js:652:18)
    at Object.fs.readFileSync (fs.js:553:33)
    at Object.Module._extensions..json (module.js:586:20)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Module.require (module.js:513:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/usr/lib/node_modules/node-sass/lib/extensions.js:7:9)
    at Module._compile (module.js:569:30)
npm ERR! Linux 4.11.9-1-ARCH
npm ERR! argv "/usr/bin/node" "/usr/bin/npm" "i" "-g" "node-sass"
npm ERR! node v8.2.1
npm ERR! npm  v2.15.12
npm ERR! code ELIFECYCLE

npm ERR! node-sass@4.5.3 install: `node scripts/install.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.5.3 install script 'node scripts/install.js'.
npm ERR! This is most likely a problem with the node-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node scripts/install.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-sass
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR!     npm owner ls node-sass
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vagrant/npm-debug.log

So, it may be a bug of npm on archlinux.

@bubenshchykov
Copy link
Owner

please try sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share} as npm suggests https://docs.npmjs.com/getting-started/fixing-npm-permissions

@bubenshchykov
Copy link
Owner

@TKOBabu might be fixed in latest version, can you try?
if issue still happens, pls report in #88 - there was a discussion there

@ankibalyan
Copy link

ankibalyan commented Mar 8, 2018

@bubenshchykov should not modify ownership / permission for bin,share, It may get worse. I've experianced.
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

just sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules} should work.

@toxdes
Copy link

toxdes commented May 23, 2018

Anyone who's going to use

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

think 100 times before. I just had to reinstall entire ubuntu cause I accidently ran

chown -R

on /usr . There's no solution if you change permissions of files that you don't even know.

@ankibalyan
Copy link

@malivp3494 I've already mentioned that above. You should have read that. 😈

@toxdes
Copy link

toxdes commented May 24, 2018

@ankibalyan yeah, but I read the solution somewhere else, and went with it. And now I regret it. There really needs to be other way around instead using chown -R

@ankibalyan
Copy link

way I do is,
Download node, npm binaries seperatly than put the excutable file path in env var $PATH rather than installing os dependents. It waorks way smothly and no need of sudo anymore.

@toxdes
Copy link

toxdes commented May 24, 2018

@ankibalyan You should comment with a short procedure here, if you have time. For future users, who are going to use this, it will help a lot.

@bubenshchykov
Copy link
Owner

hi guys, sorry to cause you problems by suggesting sudo in the comment above. i knew sudo is risky, but didn't know it could kill an entire OS :(

npm i ngrok -g should just work itself. it works fine on OSX, but I see that it fails on linux
I'll take a closer look at permissions problem, might be possible to adjust postinstall.js

@ankibalyan
Copy link

or one can follow, these steps https://docs.npmjs.com/getting-started/fixing-npm-permissions

@OZZlE
Copy link

OZZlE commented Jan 17, 2019

I was doing sudo npm install -g ngrok --unsafe-perm=true --allow-root inside my vagrant box, I just removed sudo and it worked fine :)

@amandeepmittal
Copy link

amandeepmittal commented Mar 10, 2019

@OZZlE your solution worked! Thank you so much. Though I filed an issue here #140.

@Farhan-Haseeb
Copy link

hi guys, sorry to cause you problems by suggesting sudo in the comment above. i knew sudo is risky, but didn't know it could kill an entire OS :(

npm i ngrok -g should just work itself. it works fine on OSX, but I see that it fails on linux
I'll take a closer look at permissions problem, might be possible to adjust postinstall.js

I was facing the same problem in OSX even sudodidn't work. I had to use sudo npm install -g ngrok --unsafe-perm=true --allow-root

@viatanas
Copy link

viatanas commented Jan 3, 2023

hi guys, sorry to cause you problems by suggesting sudo in the comment above. i knew sudo is risky, but didn't know it could kill an entire OS :(
npm i ngrok -g should just work itself. it works fine on OSX, but I see that it fails on linux
I'll take a closer look at permissions problem, might be possible to adjust postinstall.js

I was facing the same problem in OSX even sudodidn't work. I had to use sudo npm install -g ngrok --unsafe-perm=true --allow-root

This is what worked for me on MacOS - thanks!

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

8 participants