2

I've been using stylelint-gulp for some time now without issue. I have stylelint loaded as a npm devDependancy(ie not global, as I dont want it to be global) in my project, and following the instructions I should have the CLI available as well.

however stylelint --help returns "command not found"

I have other modules installed like eslint, and the cli works just fine.

node: v12.11.1 npm: 6.11.3

I also have nvm installed so I've tried switching back to npm --lts but it's still not working. Btw, this is on osx 10.13.6 if it matters.

any advice?

orionrush
  • 566
  • 6
  • 30

2 Answers2

4

As you don't have stylelint installed globally you won't have the stylelint command available globally.

Similar to noted in the comment above, the best way to use the stylelint command when you don't have it installed globally is to access it via a repo where you do have it installed:

./node_modules/.bin/stylelint "**/*.css"

netweb
  • 622
  • 5
  • 12
  • Yup, its my comment :) I think it's Stylelint's documentation which is at fault here. The CLI doc which I've linked to, explicitly describes `npm install stylelint --save-dev`, and then goes on to instruct running `stylelint --help` to print the documentation. How is that even possible? – orionrush Oct 04 '19 at 13:32
2

The short answer:

With any locally installed npm package (ie as a project's devDependancy), you should not expect to be able to run the package's CLI as follows <package_name> --help. You will need to include the full path to the module in the .node_moduels/ directory, just as @netweb has shown in his answer:

./node_modules/.bin/stylelint --help

IMHO Stylelint's documentation page is a tad confusing in this regard, which is why I asked the question.

The longer answer:

To be able to run stylelint --help or any other npm CLI, you would have to† install the package globally, ie: <package_name> -global. In that process, a symlink is created so the <package_name> keyword could be invoked in any directory on the system.

However, there is a category of tools (for example linters) where its usually considered bad practice to install them globally. This is because different projects will likely have conflicting requirements, in which case, having all these tools globally installed quickly becomes problematic. It's best to have these tools installed at the project level as a devDependancy like so: npm install <package_name> --save-dev.

If you are setting up an npm scripts or Continuous Integration systems then you would invoke these tools' CLI by including the path to the local install: ./node_modules/.bin/stylelint "**/*.css"

However, in the terminal, writing the fill path each and every time you want to invoke a tool is painful, so instead, you can use [npx][4] to invoke the locally installed module:

npx stylelint --help

npm-link, also symlinks your local package as if it was a globally installed. However, except for some specific scenarios, it's very unlikely you want to make globally available a local devDependancy.

orionrush
  • 566
  • 6
  • 30