cli: [Bug]: Ngrok "Failed to start the tunnel"

Please confirm that you have:

  • Searched existing issues to see if your issue is a duplicate. (If you’ve found a duplicate issue, feel free to add additional information in a comment on it.)
  • Reproduced the issue in the latest CLI version.

In which of these areas are you experiencing a problem?

App, Extension, Theme

Expected behavior

Be able to start ngrok tunnel after running through steps to create a Node.js app

Actual behavior

Throwing an error on yarn dev and erroring out.

Stack trace

/Users/robert/Desktop/usrx-custom-app/us-rx/node_modules/yoga-layout-prebuilt/yoga-layout/build/Release/nbind.js:53
        throw ex;
        ^

Error: failed to start the tunnel
    at connectRetry (/Users/robert/Desktop/usrx-custom-app/us-rx/node_modules/@shopify/ngrok/index.js:45:11)
    at async /Users/robert/Desktop/usrx-custom-app/us-rx/node_modules/@shopify/ngrok/index.js:30:17

Node.js v18.9.1
error Command failed with exit code 7.

Reproduction steps

  1. Complete setup instructions per terminal
  2. Run yarn dev

Operating System

Mac OS Monterey

Shopify CLI version (check your project’s package.json if you’re not sure)

3.37.0

Shell

bash

Node version (run node -v if you’re not sure)

v18.9.1

What language and version are you using in your application?

Node v18.9.1

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 27 (8 by maintainers)

Most upvoted comments

I went to

/project/node_modules/@shopify/ngrok/src/client.js

and went into the function that starts the tunnel and realized the package was throwing an error if ngrok didn’t connect in first 10 tries

async function connectRetry(opts, retryCount = 0) {
  if (!processUrl || !ngrokClient) {
    return;
  }
  opts.name = String(opts.name || uuid.v4());
  const response = await ngrokClient.startTunnel(opts);
  if (response) {
    return response.public_url;
  }
  if (retryCount >= 10) { // this will throw error if retires goes more than 10  so I just changed it to 20 
    throw new Error('failed to start the tunnel');
  }
  await sleep(0.2);
  return connectRetry(opts, ++retryCount);
}

so I changed the retryCount to 20 and it worked

Hope it helps in debugging

My temporary solution (replace 8898 with anything you want) (inspired by @hmthang96 comment):

  1. $ ngrok http 8898 → copy https url, for example https://2156-37-122-170-60.ngrok.io
  2. In another terminal tab: $ pnpm run dev --tunnel-url "https://2156-37-122-170-60.ngrok.io:8988" --theme-app-extension-port=8988
  3. Done

@Tomtom1410 @joeainsworth , this is a different issue, related with cloudflare not ngrok. Could you open a new issue so that we can track it properly? Please include as much info as possible: OS, terminal, node version, and if possible, run the same command with --verbose and attach the output.

Seems like the cloudflared binary is crashing trying to create the tunnel connection 🤔 Does it happen always?

Could you try to run cloudflared in a separate terminal to see if it works?

  • Find the cloudflared binary in your node modules folder. Is usually at ./node_modules/@shopify/plugin-cloudflare/bin/cloudflared (if you can’t find it you can also install cloudflared globally, instructions here)
  • run it with: cloudflared --url http://localhost:3000

It should print a URL and a message like INF Registered tunnel connection. If that works but the Shopify CLI doesn’t, you can use that URL with dev like:

pnpm shopify dev --tunnel-url {cloudflare_url}:3000

Let me know how it goes 😃

Hi there, I init a shopify app and run it, but i have an error, so i can’t run my project, I use latest CLI 3.46.0. Can you have me resolve it? I also tried with cloudflered, but it still doesn’t work This is my error:

  1. npm run dev => error image

Hi @usrx-rob have you tried to kill any potentially running ngrok process wth killall ngrok and running dev again?