2

I'm trying to use ParcelJS with Lando and there's one problem if you want HMR to work. You need to expose a port and that seems to be much harder than it should be with Lando. :(

So I know I need to do this for my ParcelJS watch command:

parcel watch dev/scripts.js --out-dir prod/ --hmr-port 6101

Then I need to expose the port I've assigned, in this case "6101" to Docker (via my Lando config file). But that's where it's tricky, apparently, because of the proxy setup Lando uses.

My current .lando.yml config is below, but it doesn't work as expected and the port is not exposed. I still get a "scripts.js:224 WebSocket connection to 'wss://testwp.lndo.site:6101/' failed:" error message from my ParcelJS generated script file in my browser's dev tools:

name: testwp
recipe: wordpress
config:
  php: '8.0'
  via: nginx
  webroot: wordpress
  database: mysql:8.0
services:
  appserver:
    portforward: 6101
Trevor
  • 2,511
  • 1
  • 14
  • 25
  • As I commented below my parcel code above was for v1, and the approved answer still didn't work in my case, but with v2 it does, you just need to change the options slightly as noted in my comment in the answer. – Trevor Aug 07 '22 at 01:32

1 Answers1

1

I saw a similar post about a problem with LocalWP which does about the same thing Lando does.

Can you maybe try to add the flag --hmr-hostname localhost.

Its ether that or --hmr-hostname testwp.lndo.site.

UPDATE:

After checking the parcel CLI docs the flag could also be --hmr-host localhost try that aswell.

Obsidianlab
  • 667
  • 1
  • 4
  • 24
  • Hey @Obsidianlab thanks for trying something here! Unfortunately for me I still have the same issue, it just changes the URL for my web socket error now to `localhost`. :( – Trevor Aug 06 '22 at 23:53
  • 1
    Actually I was using Parcel v1 for some reason and didn't realise it. I most definitely should have been using v2, and good news, when I do then your answer works! With v2 the options change a little so my npm script is now: `parcel watch dev/scripts.js --dist-dir prod/ --host localhost` – Trevor Aug 07 '22 at 01:29
  • Nice! Glad you got it to work! This kind of stuff happens its good you had the idea to check parcel versions. – Obsidianlab Aug 07 '22 at 13:53