Error occurred while trying to proxy: localhost:3000/

After switching to node 18 I’m not able to connect to the proxy via http://localhost:3000. I didn’t change any config I’m still having set the proxy and serve like this:

/**
* Proxy origin (`WP_HOME`)
 * @see {@link https://bud.js.org/docs/bud.proxy/}
*/
.proxy('http://wordpress.test/')

/**
* Development origin
* @see {@link https://bud.js.org/docs/bud.serve/}
*/
.serve('http://localhost:3000/')

this all worked fine before but not anymore. When I’m opening http://localhost:3000 I get the following message:
Error occurred while trying to proxy: localhost:3000/

Also I see errors in the console:
localhost/:1 Failed to load resource: the server responded with a status of 504 (Gateway Timeout)

But I can access http://wordpress.test directly.

Does anyone has an idea what the problem could be?

I’m not sure Node 18 is the culprit here, instead another difference in your environment. I’m assuming you’re running something like Trellis / Local / Docker.

You can resolve wordpress.test from your host machine, but can the container / VM where bud is running resolve it correctly too?

Try dig wordpress.test from inside your container / VM, it should resolve to the same that it does for the host.

If you have previously installed Laravel Valet, there may be a broken DNS server still set up for *.test domains. This thread has more information.

1 Like

hmm, I just did some tests and it really only occurs when I’m switching to node 18! everything works fine with node 16 and then, if I switch to node 18 it stops working. Even with the same versions of node_modules!

Does anyone else experience this behaviour?

Interesting. Are you able to share a minimal example?

  • How are you running your project (Docker / Trellis / Local / On host / Other)?
  • How are you switching Node versions?

I’m using ddev as local dev environment.

I made a fresh setup in this git repo:
https://github.com/herrpatrickmueller/wordpress.test

  1. Check out the repo in branch main
  2. Install composer dependencies for bedrock in document root composer install
  3. Edit the .env file to connect to the db
  4. change into the them dir web/app/themes/test
  5. install composer dependencies composer install
  6. install npm dependencies with node v16 npm ci
  7. run dev server npm run dev

Now everything should work as expected and the localhost is proxied to wordpress.test. Now change you local node version to v18. Checkout the branch node18, remove node_modules and install all npm dependencies with npm ci.

If you now run npm run dev the proxy fails. Can you reproduce this on your side? I don’t now how to make a running development environment to share with you.

Thanks. I followed a slightly different process to you, but ran npm run dev in your repo for both Node 18 and 16.

Can confirm that npm run dev behaviour is identical between Node v16.13.0 and v18.16.0, and proxy works as expected.

You mention changing the local node version, but you’re also changing the ddev node_version too. Are you running npm run dev on your local machine, or inside the ddev container? The hostname used in proxy() must resolve properly from wherever bud is running. Can you curl http://wordpress.test successfully from wherever you’re running bud dev from?

Interesting and thank you for testing it in your environment.

I’m running npm run dev on my local machine and I did not change the node version of ddev as no node task it running on the ddev machine.

I can also curl http://wordpress.test successfully from inside the ddev machine and from my local machine. This is really the strange part. Why can I access http://wordpress.test but the proxy not.

I have the same problem: I’m not able to connect to the proxy url when using Node 18. It works with Node 16.

My bud.config.js is like:

    const domain = 'mydomain';
    .proxy('https://' + domain + '.local')
    .serve({
      host: domain + '.local',
      ssl: true,
      cert: app.path('@certs/' + domain + '.local.crt'),
      key: app.path('@certs/' + domain + '.local.key'),
      port: 3000,
    })

I’m using LocalWP and setting the SSL certificate details since it is a self-signed certificate.

I notice that if I change my proxy config to .proxy('http://' + domain + '.local') WITHOUT the https, it works. Do I need to set SSL certificate details for the proxy as well? The docs at bud.proxy | bud.js don’t show any additional config options for .proxy().

Hi @jeremylind,

It sounds to me like this is a different issue to the OP.

Can you check and see if setting the env var NODE_TLS_REJECT_UNAUTHORIZED to "0" allows the proxy to work? ie:

NODE_TLS_REJECT_UNAUTHORIZED="0" yarn dev

If so, it seems to me like the self signed CA isn’t set up correctly on your machine, or possibly (if you’re running Node 18 in a container or VM), the CA cert isn’t even installed.

I’m sure you’re probably aware of the issues with LocalWP self-signed CA installation on Mac Big Sur and newer.

I’m not suggesting setting NODE_TLS_REJECT_UNAUTHORIZED long term - that’s a bad idea.

Yeah, that didn’t work. But I think you are on to something about LocalWP. It looks like Node versions after 16 use OpenSSL 3, which may not support the certs generated by LocalWP? Node has a CLI flag to enable legacy support, --openssl-legacy-provider (Command-line API | Node.js v20.5.0 Documentation), but I’m not sure how to enable that flag for bud. This is above my pay grade, so I might need to leave it!