Magento 2 Grunt – Fix Grunt Fail to Run After Upgrade

gruntmagento2

After upgrade from v2.1.8 to v2.2.2, error is shown when i run Grunt exec

$ grunt exec
Loading "Gruntfile.js" tasks…ERROR

Error: Cannot find file. Alias "themes" not set. Use "filesRouter.set" method to set it.
at Object.get (/var/www/vhosts/default/dev/tools/grunt/tools/files-router.js:69:19)
at Object. (/var/www/vhosts/default/dev/tools/grunt/configs/clean.js:8:47)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at module.exports (/var/www/vhosts/default/node_modules/load-grunt-config/lib/readfile.js:22:16)

Best Answer

Because in M2.2 there is a new grunt config file : grunt-config.json

http://devdocs.magento.com/guides/v2.2/frontend-dev-guide/tools/using_grunt.html

so we have to install it again, and update grunt-config.json

from "themes": "dev/tools/grunt/configs/local-themes"

To "themes": "dev/tools/grunt/configs/themes"

Also you may got this error "node-gyp: relocation error: node-gyp: symbol SSL_set_cert_cb, version libssl.so.10 not defined in file libssl.so.10 with link time reference"

Run

yum update openssl

Then execute

npm install npm update