Today I am trying to execute grunt exec:all and grunt exec commands. Unfortunertly it shown me a error. Earlier it was working fine. Later I had try to install new Magento 2 setup. Still the error is same:

error preview

I stuck over here.

I tried following with the help of devdocs:

  • re-install nodejs
  • re-install npm
  • re-isntall grunt-cli
  • re-install grunt

Other tools/commands are working fine for grunt like grunt less:luma and at all. Only the issue is into grunt exec.

Can anyone suggest me what is going wrong here? in magento 2?

3 Answers 3


grunt exec is esentially a shorthand for clearing the folders var/view_preprocessed, var/generation, var/log/system.log and pub/static and running

php bin/magento dev:source-theme:deploy --type=less --locale=en_US --area=frontend --theme=Package/theme

So before running grunt commands you need to make sure that your comand line php is the same as the server php and that it has access to the database.

  1. Make sure that the user with which you are running grunt has access to delete the var and pub/static folders.
  2. Check the permissions on bin/magento and make sure it is a+x (your issue).
  3. Make sure you're running grunt from the folder where the Gruntfile.js is located.
  • This is the solution that most often works for me. When i run into this issue, it's because there are files in the pub/static folder that need to be removed before grunt can perform it's magic. The same can happen in the var folder, but less often this is the issue.
    – circlesix
    Sep 11, 2016 at 3:48

Try to run your cmd/console as administrator then run that commands again.


You've written you've re-installed grunt but are you sure it's installed locally? If so, it there should be grunt folder in node_modules. If not, try running npm install in the project root directory.

I'm not entirely sure if it's possible to run Grunt tasks without local grunt package being present, but this would explain some tasks working fine with grunt-cli still complaining about not being able to find local grunt for others.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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