cli icon indicating copy to clipboard operation
cli copied to clipboard

netlify dev could not connect to target server after long time out

Open robations opened this issue 3 years ago • 7 comments

Describe the bug

The netlify dev command correctly starts the gatsby server on port 8000, which is then running correctly.

The most common scenario is there is a long pause (>10 minutes) then dev server says it can't connect to port 8000 and exits with an error code of 1. On one occasion it connected correctly (after the same long wait).

At some point a few months ago this was working fine, unsure which dependency/environment/cli change has broken it.

To Reproduce

Steps to reproduce the behavior:

  1. Run git clone private git repo
  2. Navigate to the cloned repository
  3. Run netlify dev
  4. See that the CLI exits with an error

Bear with me while I work on this. A discussion about this issue might help me or other people. Not at all easy to reproduce bugs with such complicated systems, e.g. do I need to set up another copy of WordPress for this reproduction? Please, tell me no...

Configuration

  • If possible, please copy/paste below your netlify.toml.
  • Please enter the following command in a terminal and copy/paste its output:
$npx envinfo --system --binaries --npmPackages netlify-cli --npmGlobalPackages netlify-cli

  System:
    OS: macOS 11.6
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.10.0 - ~/.asdf/installs/nodejs/16.10.0/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 7.24.0 - ~/.asdf/installs/nodejs/16.10.0/bin/npm

Expected behavior

Expecting dev server to connect to localhost:8000 shortly after gatsby has finished processing and has opened a port.

CLI Output

You can now view my-project-name in the browser.
⠀
  http://localhost:8000/
⠀
View GraphiQL, an in-browser IDE, to explore your site's data and schema
⠀
  http://localhost:8000/___graphql
⠀
Note that the development build is not optimized.
To create a production build, use gatsby build
⠀
success Building development bundle - 97.505s
⠀
info  gatsby-source-wordpress  Watching for WordPress changes
success Writing page-data.json files to public directory - 1.692s - 147/147 86.87/s
success write out requires - 0.141s
[ LONG WAIT AT THIS POINT ]
◈ Netlify Dev could not connect to localhost:8000.
◈ Please make sure your framework server is running on port 8000
Waiting for the debugger to disconnect...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Waiting for the debugger to disconnect...

Process finished with exit code 1

Additional context

Is netlify dev waiting for some kind of signal/event from the child process to connect, or is it polling on a regular basis?

NB the output log above is running with the debugger but it fails in the same way without the debugger.

robations avatar Nov 30 '21 12:11 robations

I assumed netlify-cli was installed locally (and thus up-to-date) but turns out it was a global installation through homebrew.

After upgrading (6.9.30 -> 7.1.0) it looks like it's working as expected.

robations avatar Nov 30 '21 12:11 robations

I have this issue again with all Netlify cli versions I've tried:

# homebrew global install
netlify-cli/8.13.0 darwin-x64 node-v16.10.0

# devDep (before upgrade)
netlify-cli/8.17.3 darwin-x64 node-v16.10.0

# devDep (after upgrade)
netlify-cli/9.4.0 darwin-x64 node-v16.10.0

Each time gatsby (v3) finishes with:

info  gatsby-source-wordpress  Watching for WordPress changes
success Writing page-data.json files to public directory - 3.865s - 149/149 38.55/s
success write out requires - 0.025s

Then I get after a long pause:

◈ Netlify Dev could not connect to localhost:8000.
◈ Please make sure your framework server is running on port 8000
error Command failed with exit code 1.

It's possible that gatsby is at fault. Open to ideas on how to debug this dialogue between the two platforms.

robations avatar Feb 14 '22 12:02 robations

having the exact same problem on node v17.5.0, gatsby 4.11.2 and netlify-cli ^9.13.2

novelnet avatar Apr 11 '22 11:04 novelnet

Nope, same issue here on SvelteKit.

reesericci avatar Apr 17 '22 04:04 reesericci

Solved the issue for me, having an index.js placeholder in src/pages/ (as i usually only used src/pages/de/ with locale redirect: domain.com/de/)

const IndexPage = () => {
  return ""
}

export default IndexPage

novelnet avatar Apr 23 '22 12:04 novelnet

Having the same time out issue with stopping Netlify dev server when 10 or so minutes passed. I'm using Netlify dev server for functions and Vite as web server. netlify-cli/10.1.0 win32-x64 node-v17.3.0 Error message from Netlify dev server:

Netlify Dev could not connect to localhost:3000.
Please make sure your framework server is running on port 3000

whereas my website is accessible on localhost:3000.

bomzj avatar May 04 '22 11:05 bomzj

For some reason my problem has been resolved by enabling my VPN service on my computer / switching from on network to the other. It seems unrelated since you're running a localhost server but I thought to mention it here anyway.

jorislive avatar Jul 03 '22 12:07 jorislive

Some of these issues should be fixed now as of version 12.0.2. If it still appears please reopen with an example.

danez avatar Sep 30 '22 09:09 danez