3

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?

Esther
  • 71
  • 1
  • 1
  • 8
  • 1
    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. – Yash Khorja Jul 24 '20 at 08:12

7 Answers7

4

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.

Esther
  • 71
  • 1
  • 1
  • 8
  • 1
    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! – Spencer Hill Dec 07 '17 at 05:28
  • 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.) – user3067860 Jul 14 '21 at 17:47
3

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

browserSync.init({
    server: "./src",
    firefox: '-browser "firefox.exe"'
}
Smittey
  • 2,475
  • 10
  • 28
  • 35
jeff
  • 31
  • 1
1

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.

Ashim Sth
  • 131
  • 1
  • 6
0

I tried this command and it worked for me:> browser-sync start --server --browser "chrome.exe" --directory --files "*"

0

you have to change something in Packages.congig file in visual studio

{

"port": 3000,

"server": {

"baseDir": "."

},

"browser": ["chrome"]

}

It worked in my computer, you should try it at once

Ghonima
  • 2,978
  • 2
  • 14
  • 23
-1

I also had the same problem.

Open your favourite browser and in the search bar explicitly write the local access URL just mentioned above the error you got in the command promt like localhost:3002. You might have got port number like 3000 or 3001 there. Press enter and Browsersync would be connected and index.html is executed.

I hope this works for you as well!

Bhavdeep Kaur
  • 89
  • 1
  • 2
  • Hi Bhavdeep, welcome to SO! Please read up on [writing a good answer](https://stackoverflow.com/help/how-to-answer) before answering you next question. Enjoy your stay :) – Diggy. May 13 '20 at 15:57
-1

Just running cmd as admin might solve the problem

DevilWhite
  • 51
  • 6