dockerparceljs

What causes `Error: spawn xdg-open ENOENT` when running Parcel in Docker?


I have a React SPA that that uses Parcel as the build tool/dev server. I'm trying to get it running inside a Docker container, but when I run the parcel serve command, I get an error like this:

$ parcel src/index.html --open --port 3000
node:events:492
      throw er; // Unhandled 'error' event
      ^
Error: spawn xdg-open ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:289:12)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn xdg-open',
  path: 'xdg-open',
  spawnargs: [ 'http://localhost:3000' ]
}

What would cause this?


Solution

  • Figured it out!

    As you can see in the output, I ran the parcel serve command with the --open flag (that's how it was set up in the package.json script). The problem is, that flag tells Parcel to try to open the app in a browser window which doesn't make sense in the context of a Docker container.

    Removing the --open flag fixed the issue.