timonweb / django-tailwind

Django + Tailwind CSS = 💚
https://django-tailwind.readthedocs.io
MIT License
1.46k stars 92 forks source link

App should make an attempt to retrieve the NPM path #83

Closed MichaelGatesDev closed 3 years ago

MichaelGatesDev commented 3 years ago

I am just getting started with django-tailwind and I received the following error:

CommandError: 
It looks like node.js and/or npm is not installed or cannot be found.

Visit https://nodejs.org to download and install node.js for your system.

If you have npm installed and still getting this error message, set NPM_BIN_PATH variable in settings.py to match path of NPM executable in your system.

Example:
NPM_BIN_PATH = "/usr/local/bin/npm"

The error makes it seem like the app tried to find a path to NPM or actually tried to use it. But according to this file, it will only ever be retrieved from a django settings file.

I think that it is quite likely that a user's system has NPM installed globally, so if a user does not explicitly set NPM_BIN_PATH, it should just assume that npm is available globally and should attempt to run the subprocess as subprocess.run(["npm"] + list(args), cwd=self.cwd) (how to run npm in subprocess without an absolute path to the executable).

justinmayer commented 3 years ago

I believe the project already behaves as you propose, since as the corresponding documentation states, the default value of NPM_BIN_PATH is npm.

Following the principle of "explicit is better than implicit", I don't think Django-Tailwind should do any more than it currently does to locate the NPM executable. As noted in the above documentation, if Django-Tailwind can't find the executable, instructions are clearly provided regarding how to specify the desired executable. (And there can often be multiple NPM executables on a system, ergo why being explicit is preferred.)

timonweb commented 3 years ago

@MichaelGatesDev you can change npm bin path as stated in the docs. Please see a link in James' comment above.