简体   繁体   English

浏览器未通过 BrowserSync 或实时服务器启动

[英]Browser not launching with BrowserSync or live-server

I've been using live-server with VS Code to debug some web pages.我一直在使用带有 VS Code 的 live-server 来调试一些网页。 Everything was fine, I ran live-server from my command line in the page directory and Chrome opened a new tab with the page.一切都很好,我从页面目录中的命令行运行live-server ,Chrome 打开了一个包含该页面的新标签页。

Then suddenly it stopped working!然后突然它停止工作了! I though it was a bit weird so I installed Nodejs again and an issue appeared afterwards.我觉得这有点奇怪,所以我再次安装了 Nodejs,之后出现了一个问题。 The server is working but it isn't able to open Chrome (nor any other Browser)服务器正在工作,但无法打开 Chrome(或任何其他浏览器)

I tried using BrowserSync instead of live-server and again, the server works but it isn't able to automatically open Chrome我尝试使用 BrowserSync 而不是实时服务器,再次,服务器可以工作,但无法自动打开 Chrome

I can always manually type http://localhost:3000 but I shouldn't (since it worked before)我总是可以手动输入http://localhost:3000但我不应该(因为它以前工作过)

I've tried uninstalling and installing both live-server and browserSync, Chrome.我试过卸载和安装 live-server 和 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:刷新我的 dns,检查恶意软件,检查 Windows 防火墙是否阻止了任何相关的事情,以及其他一些没有为我做任何事情的事情,我仍然得到:

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.出现问题是因为不知何故 C:\\Windows\\System32 不在系统路径变量中。 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.标记的答案实际上对我不起作用,但在 init 函数中手动设置浏览器属性。

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我正在运行 Windows 10 x64

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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