Browser not launching with BrowserSync or live-ser

2019-02-15 14:11发布

问题:

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?

回答1:

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



回答2:

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