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

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

Closed
sarink opened this issue Jan 27, 2022 · 3 comments
Closed

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

sarink opened this issue Jan 27, 2022 · 3 comments

Comments

@sarink
Copy link

sarink commented Jan 27, 2022

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 (#229), which is apparently ECONNREFUSED

After some more digging, I found #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
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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.

@philnash philnash closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
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