Magento 2 – DB Error When Running Grunt Exec

frontendgruntmagento2theme

I am running grunt exec:luma and am getting the following errors:

Processed Area: frontend, Locale: en_GB, Theme: Magento/luma, File type: less.

>>   [Zend_Db_Adapter_Exception]
>>   SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
>>
>>
>>   [PDOException]
>>   SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
>>
>>
>>
>> dev:source-theme:deploy [--type="..."] [--locale="..."] [--area="..."] [--theme="..."] [file1] ... [fileN]
>> Exited with code: 255.
Warning: Task "exec:luma" failed. Use --force to continue.

Aborted due to warnings.

enter image description here

Steps I have taken are as follows:

  1. Clean theme by command: grunt clean

  2. run command: grunt exec:yourthemename

I don't have a clue why I am getting a DB error can anyone shed any light into this. DB credentials I'm just confused as to why the Grunt task would be even interacting with the DB.

My Magento 2 set up is running on an Nginx server

Best Answer

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. You get that error because your comand line php does not have access to the database. Also make sure that the user with which you are running grunt has access to delete the var and pub/static volders.