BROWSER SYNC headless environment ERROR

安稳与你 提交于 2020-02-25 06:41:48

问题


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?


回答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.




回答2:


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

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



回答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.




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/44432953/browser-sync-headless-environment-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!