简体   繁体   中英

Browser not launching with BrowserSync or live-server

I've been using live-server with VS Code to debug some web pages. Everything was fine, I ran live-server from my command line in the page directory and Chrome opened a new tab with the page.

Then suddenly it stopped working! I though it was a bit weird so I installed Nodejs again and an issue appeared afterwards. The server is working but it isn't able to open Chrome (nor any other Browser)

I tried using BrowserSync instead of live-server and again, the server works but it isn't able to automatically open Chrome

I can always manually type http://localhost:3000 but I shouldn't (since it worked before)

I've tried uninstalling and installing both live-server and browserSync, Chrome. Flushing my dns, checking for malware, checking if Windows Firewall is blocking anything related, and some other things that hadn't done anything for me, I still get the:

Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option to false)

as seen here

Can someone please tell me what could be causing this issue or how should I attempt to fix it?

The problem occurred because somehow C:\\Windows\\System32 was not in the System Path Variable. I just added it again, restarted the computer and it works fine again

The marked answer didn't actually work for me but manually setting the browser property in the init function did.

gulp.task('browserSync', () => {
        browserSync.init({
            server: {
                baseDir: task.dir.base,
                middleware: [
                    webpackDevMiddleware(bundler, {
                        publicPath: webpackConfig.output.publicPath,
                        stats: 'errors-only'
                    })
                  ]
            },
            browser: 'chrome'
        });
    });

I'm running windows 10 x64

好吧,这对我不起作用,但我尝试了其他方法,它工作正常,只需转到该文件 default-config.js 您在您的项目文件夹 node_modules\\browser-sync\\dist 中找到它并查找 => 浏览器:“默认",你所要做的就是将默认值更改为你的实际浏览器,对我来说它是'chrome.exe'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM