BrowserSync / browser-sync

Keep multiple browsers & devices in sync when building websites. https://browsersync.io
https://discord.gg/2d2xUThp
Apache License 2.0
12.14k stars 754 forks source link

Not working on node@^20.0.0 #2039

Closed firefoxic closed 9 months ago

firefoxic commented 1 year ago

Issue details

The problem was noticed when using browser-sync via gulp. But it turned out that it had nothing to do with gulp. Both methods I used to start browser-sync (CLI and gulp), which worked fine up to and including node@19, turned out not to work in node@20.

Steps to reproduce/test case

  1. Install node@20 with any node version manager, such as nvm, nvs or volta.

  2. Create a test directory and move into it:

    mkdir test-bs && cd test-bs
  3. Create the minimum required index.html:

    echo '<!DOCTYPE html>' > index.html
  4. Try to start the server:

    npx browser-sync start -s

Please specify which version of Browsersync, node and npm you're running

Affected platforms

Browsersync use-case

If CLI, please paste the entire command below

npx browser-sync start -s

Screenshot of a terminal with a browser-sync test in different versions of node.js: in v20.4.0 it crashes with `AggregateError` output, but in v18.16.1 it works correctly running the server.

trusktr commented 9 months ago

I tried it, and it worked for me on Node 20 actually! Wasn't able to reproduce. However with that index.html, live reload won't work.

Live reload requires a <body> like this:

echo '<body>hello</body>' > index.html

The body tag has to be present for the script injection to work (I think it is possible browser-sync could simply inject the script regardless).

shakyShane commented 9 months ago

Thanks for the ping, yep I'll look at this ASAP :)

shakyShane commented 9 months ago

@trusktr

I think it is possible browser-sync could simply inject the script regardless

I tried that before, it's way too problematic - I know the restriction is annoying, but you can always configure https://browsersync.io/docs/options#option-snippetOptions to get around it.

I updated the GitHub actions to run on Node 20 now - and everything is passing.

@firefoxic - could you try with a more realistic HTML example and report back if it's working for you :)