1

Documentation at https://devdocs.magento.com/guides/v2.3/frontend-dev-guide/tools/using_grunt.html states to install grunt using the -g (global) command, which requires elevated privileges. Unfortunately many shared hosting systems out there exist which cannot allow installing binaries globally.

It appears that this may be required if you want to use grunt - and thus be able to output source map files, giving one the ability to develop a Magento 2 frontend with some semblance of efficiency.

OK, so what if you can't install it globally? I installed npm directly to the magento root folder along with grunt-cli and lessc. I run grunt by referencing its full path name: "~/public_html/node_modules/grunt-cli/bin/grunt". With a properly configured themes.js (or custom-themes.js and a modified grunt-config.json that points to it), attempting to run the exec task against the blank theme results in an error:

[public_html]$ ./node_modules/grunt-cli/bin/grunt exec:blank
Running "exec:blank" (exec) task
>> /bin/sh: grunt: command not found
>> Exited with code: 127.
>> Error executing child process: Error: Process exited with code 127.
Warning: Task "exec:blank" failed. Use --force to continue.

Aborted due to warnings.


Execution Time (2020-05-12 22:13:15 UTC-0)
loading tasks       87ms
▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 78%
loading grunt-exec   2ms  ▇▇ 2%
exec:blank          23ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇ 21%
Total 112ms

I presume that some additional modification within the myriad of .js files in the /dev/tools/grunt folder is required. Anyone have any knowledge about this? Trying to search through .less files for css classes is extremely cumbersome.

2
  • "develop a Magento 2 frontend with some semblance of efficiency". No chance of that one sorry (unless you go down the headless route)
    – Ben Crook
    May 13, 2020 at 16:57
  • 1
    Haha I should have said relative May 13, 2020 at 20:25

1 Answer 1

2

The answer is, NO, it is not necessary! The solution is to simply add the path to grunt to your $PATH variable. If your path is ~/public_html/node_modules/grunt-cli/bin/grunt, then in Centos for example, you would type:

export PATH=$PATH:~/public_html/node_modules/grunt-cli/bin/grunt 

The same should be done for the lessc binary as well:

export PATH=$PATH:~/public_html/node_modules/less/bin/lessc

Additionally, to make this permanent, add the same lines to your shell's profile file, ie, .bash_profile for bash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.