Search code examples
parceljs

Command in parcel.js --open 'google chrome' does not work on Windows, only works on MacOS


I use parcel.js to set up my project. This command --open 'google chrome' does not work on Windows, only works on MacOS. The error is: Windows cannot find 'google'. Make sure you typed the name correctly, and then try again.


Solution

  • The browser value passed to --open [browser] is platform-dependent:

    • Windows: chrome
    • Linux: google-chrome
    • MacOS: google chrome

    Parcel uses the opn package to start the browser. From the opn documentation:

    Type: string | string[]

    Specify the app to open the target with, or an array with the app and app arguments.

    The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is google chrome on macOS, google-chrome on Linux and chrome on Windows.

    You may also pass in the app's full path. For example on WSL, this can be /mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe for the Windows installation of Chrome.