BROWSER SYNC headless environment ERROR

15,330

Solution 1

So while I kept browsing, i found a clue to the solution of this problem on this webpage https://gist.github.com/Kenty/9096000/revisions which hinted me of where i could find the open option from the error message. I decided to searched for "bs.config.js" on my pc and i found a file called default.config.js in my \Template\node_modules\browser-sync\lib folder under my angular folder and when i searched through the file, i finally found the open option and changed the open option from "local" (which is the default option) to false (Note, it's without the quotes) and when i ran the npm start command again, on the git-bash terminal It worked and there were no more errors.

Solution 2

Add browser attribute, for instance to use firefox : firefox: '-browser "firefox.exe"'

browserSync.init({
    server: "./src",
    firefox: '-browser "firefox.exe"'
}

Solution 3

A related question https://stackoverflow.com/a/42845813/8130472 was answered and suggested the option of adding C:\Windows\System32 to the System Variables but i don't know how to go about it

About adding to system variables, you can go to "This Pc" properties then to left side bar "advanced system settings" then at bottom you will see "environment variables". You will see Path variable listed double click and copy paste above path i.e C:\Windows\System32

After restart this really solved my browsersync problem.

Share:
15,330
Esther
Author by

Esther

<me style="my-style">I like coding, I'm not much of a crazy coding enthusiast but i just do what i have to do. I'm a computer Science Student in Nigeria and I'd love to learn a lot from this forum.</me>

Updated on June 04, 2022

Comments

  • Esther
    Esther almost 2 years

    So i just started learning Angular 2 and after running the npm install command on git bash and opening my text editor, I was trying to run the npm start command to start the typescript and lite server. Everything went well until this error showed up [1] [BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false) and the browser didn't open. Here's how it looks `

    $ npm start
    
    [1] [BS] Access URLs:
    [1]  --------------------------------------
    [1]        Local: http://localhost:3002
    [1]     External: http://172.30.31.239:3002
    [1]  --------------------------------------
    [1]           UI: http://localhost:3003
    [1]  UI External: http://172.30.31.239:3003
    [1]  --------------------------------------
    [1] [BS] Serving files from: ./
    [1] [BS] Watching files...
    [1] [BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)
    `  
    

    I'm using a Windows 8 64bit OS and Chrome is the default browser

    A related question https://stackoverflow.com/a/42845813/8130472 was answered and suggested the option of adding C:\Windows\System32 to the System Variables but i don't know how to go about it.

    Also, on this link, https://forums.bignerdranch.com/t/browser-sync-couldnt-open-browser/10936/4 another suggestion was to add the --browser"chrome.exe"(Windows). That didn't work either.

    Any suggestions? Or Solutions?

    • Yash Khorja
      Yash Khorja almost 4 years
      I just added PATH variable in "System Variable" as C:\Windows\System32 and after restart it worked. Still I don't know what it does and how it helped to remove error. So please, if anyone knows how it removes error by adding path variable, let me know.
  • Spencer Hill
    Spencer Hill over 6 years
    I am using Roots.io's stack with Trellis, Bedrock and Sage Theme (8.x) and my configuration file was named default-config.js and it was located in node_modules/browser-sync/lib/ around line 256. When I tried searching for the filename yours was located in I didn't get any results back. So hopefully this helps someone else. Thank you for posting your solution!
  • JJJ
    JJJ about 5 years
    Please don't write code-only answers. How does it work, what does it do?
  • Diggy.
    Diggy. almost 4 years
    Hi Bhavdeep, welcome to SO! Please read up on writing a good answer before answering you next question. Enjoy your stay :)
  • user3067860
    user3067860 almost 3 years
    Note that this just prevents the browser from automatically opening at all. If you want the browser to automatically open, you need a different solution. (And if you are only running locally and do not care that the browser doesn't open automatically, then you can just ignore the "couldn't open browser" warning.)