Search code examples
node.jsnpmbrowser-sync

BrowserSync: command not found after installing locally


I ran the following command for my node app:

$ npm install browser-sync --save-dev

Installation was successful, browser-sync appears in my package.json file as well as my node_modules directory.

However, when I run $ browser-sync --version to check that it's working, I get the following error:

bash: browser-sync: command not found

Why isn't this working?

Note: this question is similar, but I don't want to have to install it globally as in this question.

Any help would be greatly appreciated!


Solution

  • This is because you're trying to use a module locally which is normally installed globally. Modules installed globally end up on your PATH environment variable, which is why you can run them from the terminal as you're trying to do:

    $ browser-sync --version
    

    If you want to use the browser-sync module from a local install you will have to prepend the full path to the browser-sync binary from within your .bin directory since all locally installed modules are placed within your current working directory node_modules directory. i.e. Node modules go in ./node_modules, executables go in ./node_modules/.bin/. So in order to run the browser-sync binary from a local install do the following:

    ./node_modules/.bin/browser-sync  --version
    

    Hopefully that helps!