bubenshchykov / ngrok

Expose your localhost to the web. Node wrapper for ngrok.
https://ngrok.com
2.33k stars 317 forks source link

TypeError: Cannot read properties of undefined (reading 'body') #264

Closed sarink closed 2 years ago

sarink commented 2 years ago

I can't seem to make this module work at all

// index.js
const ngrok = require('ngrok');
ngrok.connect().then(console.log);
$ node index.js

  TypeError: Cannot read properties of undefined (reading 'body')
    at NgrokClient.request (/Users/sarink/Projects/ngrok-doesnt-start-example/node_modules/ngrok/src/client.js:40:26)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async connectRetry (/Users/sarink/Projects/ngrok-doesnt-start-example/node_modules/ngrok/index.js:29:22)

I tried digging through the source to reveal the real error (https://github.com/bubenshchykov/ngrok/issues/229), which is apparently ECONNREFUSED

After some more digging, I found https://github.com/bubenshchykov/ngrok/issues/138 which led me to look at my auth token (in my actual app where I'm using this I set an auth token, but in the sample demo repo I made to test this issue, I did not).

That's when I noticed a ~/.ngrok/asdfasdf-some-guid-asdfasf.zip file - what is this? Whatever script wrote this presumably also is what moved my original ~/.ngrok folder (the one which has a config.yml that contains my auth token) to ~/.ngrok2.

rm -rf ~/.ngrok
mv ~/.ngrok2 ~/.ngrok

Fixed everything

Why did this happen?

philnash commented 2 years ago

The default configuration file location for ngrok is ~/.ngrok2/ngrok.yml. Though I believe that ngrok version 1 stored its config in ~/.ngrok/.

This module actually downloads and stores its own copy of the ngrok binary within ${PROJECT_DIRECTORY}/node_modules/ngrok/bin so it should have had no effect on things inside your home directory. My guess for ~/.ngrok/asdfasdf-some-guid-asdfasf.zip is that the ngrok binary itself downloads it as part of its own update mechanism.

Are you still running ngrok version 1 outside of this module? Or have you configured a different location for the config file?

I acknowledge the ECONNREFUSED error and that it causes another error because the library doesn't handle it. I've just been unable to reproduce the error myself and #231 fails the existing tests. Reading back through the issues shows that there are reports of having ngrok open on a different machine causing this issue, which is something I can look into.

philnash commented 2 years ago

I just tried running ngrok with a free account and then tried to run ngrok with the same account from this module and I did get an error, but it was expected. It was a NgrokClientError: failed to start tunnel error. So the module correctly handles it when ngrok can't start because it's already open elsewhere for the account.

philnash commented 2 years ago

There haven't been any further comments on this since January, so I am going to close the issue for now. If there are still questions or issues, please feel free to reopen.