rails / webpacker

Use Webpack to manage app-like JavaScript modules in Rails
MIT License
5.31k stars 1.47k forks source link

Raise a more accurate error when 'which_command' is not installed #3245

Closed katorres02 closed 2 years ago

katorres02 commented 2 years ago

I have a custom Centos docker image with a ruby on rails project setup. I was getting the following error during the precompile task.

bundle exec rails assets:precompile

this is the error output:

.
.
.
I, [2021-12-21T17:28:19.287300 #1]  INFO -- : Writing /usr/local/project/public/assets/express/lib/application-98f164ad65010340ab481475a0137ee982cf4de44f0e4c6441263ebb2b676481.js.gz
sh: which: command not found
sh: which: command not found
Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/
Exiting!

The command '/bin/sh -c PRECOMPILE_ASSETS_FLAG=true RAILS_GROUPS=assets bundle exec rake assets:precompile' returned a non-zero code: 1

The final message indicates that Node.js is not installed which is incorrect. Node is already installed and working, the problem here is my Centos image doesn't have the "which" command activated/installed.

According to the GNU error codes: https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html The error Errno::ENOSYS will be more accurate for this sceneario.

Macro: int ENOSYS “Function not implemented.” This indicates that the function called is not implemented at all, either in the C library itself or in the operating system.

justin808 commented 2 years ago

@katorres02 could you test out using type rather than which in your PR?

katorres02 commented 2 years ago

@katorres02 could you test out using type rather than which in your PR?

@justin808 thanks for taking the time to review this pr. in my Centos docker image the type which command didn't work using those special quotation marks. (type is installed) image

I used system("type which") instead. it returns nil if the which_command binary is not installed

Why should webpacker be responsible for ensuring items like which, node, and yarn are installed?

if webpacker is not responsable about that, can we consider removing the check_node rake task?

guillaumebriday commented 2 years ago

We probably should remove everything related to the which_command here

katorres02 commented 2 years ago

We probably should remove everything related to the which_command here

makes sense

guillaumebriday commented 2 years ago

Nice thanks @katorres02