2

I have been following a few tutorials to try and get started creating a theme and workflow for Magento 2, and am trying to setup so that I can compile all my LESS files locally, as outlined here.

The problem I am having is running grunt exec:mytheme from the root of my Magento installation. I just receive the following error:

A valid Gruntfile could not be found. Please see the getting started guide for more information on how to configure grunt: http://gruntjs.com/getting-started Fatal error: Unable to find Gruntfile.

I have added the neccessary code to the existing dev/tools/grunt/config/themes.js:

mytheme: {
    area: 'frontend',
    name: 'mytheme/default',
    locale: 'en_US',
    files: [
        'css/styles'
    ],
    dsl: 'less'
}

However I am still receiving the missing gruntfile error. Can anyone shed some light on this?

2
  • Can you confirm the gruntfile.js is in the root of your project? And are you running this from inside the server or on your local machine?
    – Ben Crook
    Commented Jun 17, 2016 at 16:31
  • There isn't a gruntfile in the root of my project, as every tutorial I've come across doesn't mention the need for one since it's handled in Magento's theme.js file. I find this odd, and I'm therefore unsure what I should be putting in my grunt file, as surely this would make Magento's theme.js redundant, no?
    – wickywills
    Commented Jun 17, 2016 at 16:38

2 Answers 2

6

You always need a Gruntfile.js to run grunt (as far as I'm aware) so if you don't have this file in your root directory I'm fairly certain this is the cause of your problem. I think the only purpose of themes.js is to add/remove themes for Grunt.

Do you have Gruntfile.js.sample in your root? You should have looking at the Magento2 repo. Just rename this to Gruntfile.js and try again.

2
  • 1
    Ok, thanks for clarifying - I guess I was just thrown off track a bit given that no tutorials mention a gruntfile in the root. Thought Magento 2 was doing some sort of magic with its theme.js file! Renamed the sample so that it's being used, all seems to work fine. Most confusing front end setup I've seen! Maybe it will make perfect sense in a few months time :)
    – wickywills
    Commented Jun 17, 2016 at 16:56
  • Yeah their instructions aren't very helpful if you don't have previous Grunt experience, it's good they're progressing with front-end tools though.
    – Ben Crook
    Commented Jun 20, 2016 at 8:31
2

I looked over the tutorial and it seems they never instruct you to install node or npm. From the source I followed here on a Ubuntu box I installed it this way.

Make sure you have npm and node installed globally on the server and is updated

sudo apt-get update
apt-get install nodejs
sudo apt-get install npm
sudo npm install -g grunt-cli

The from inside your Magento site root

npm install grunt --save-dev
npm install
npm update
npm install grunt-contrib-less

If all these are installed and updated, I have never had success with calling out just my theme with exec. When I start work in the morning I run grunt exec which will compile all the themes in the config/themes.js file. It just takes a few seconds. Them I run grunt watch and work on my styles, checking every so often to make sure that make saves are being seen by grunt and compiling without error.

3
  • Thanks for the reply, however grunt, npm and node are installed both on the server (Ubuntu) and on my local computer. I am able to do "grunt --help" and list out all the commands available. When running grunt exec, however, I still receive "gruntfile could not be found..". Just to be clear, do I need a gruntfile in the root of my project? How does grunt know to use theme.js, or am I missing something obvious?
    – wickywills
    Commented Jun 17, 2016 at 16:35
  • Take a look at this guy. github.com/magento/magento2/blob/develop/Gruntfile.js.sample
    – circlesix
    Commented Jun 17, 2016 at 16:54
  • I think running npm install grunt --save-dev is redundant in this case as that should be included in package.json already. Commented Dec 12, 2016 at 12:35

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.