Problem

I had a react project that was originally worked in windows environment. I migrated to ubuntu environment and attempted to start project with webpack-dev-server. After installing all npm packages, I encoured the following error

$ npx webpack-dev-server
ℹ 「wds」: Project is running at http://localhost:8080/
ℹ 「wds」: webpack output is served from /
ℹ 「wds」: Content not from webpack is served from /home/chadrick/prj/web/timeline2
events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: spawn chrome ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:232:19)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:238:12)
    at onErrorNT (internal/child_process.js:407:16)
    at process._tickCallback (internal/process/next_tick.js:63:19)

Solution

This was caused because of my webpack-dev-server open config. Here is the devserver config in webpack.config.js

devServer: {
        open: 'chrome',
        index: "template.html"
    }

The problem was that I have set open to "chrome" which was the binary filename for opening chrome in windows. In ubuntu, the binary command for opening chrome is google-chrome.

After I changed the value of open to google-chrome, the webpack-dev-server start worked.

devServer: {
        open: 'google-chrome',
        index: "template.html"
    }

1 Comment

anonimous squirrel · July 11, 2020 at 2:28 am

exactly what i was looking for, i have an extra setup of my dev enviroment working in ubuntu this was causing it to fail. thanks

Leave a Reply

Your email address will not be published.