Question

I can't seem to be able to use Grunt to compile my less files in my custom theme. I have done all steps described in the documentation.

My theme name is "alliance" so here is what I am trying to do and the output:

$ grunt clean:alliance

/Users/admin/Sites/new/docroot/node_modules/node-minify/node_modules/babel-preset-babili/lib/index.js:32
      get() {
         ^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token (
Warning: Task "clean:alliance" not found. Use --force to continue.

Aborted due to warnings.

I am using an exact copy of the Gruntfile.js.sample file which I renamed to Gruntfile.js and which doesn't seem to contain any syntax error, so I am a bit lost with this error message.

Any idea? Is there an issue with the current version of the Gruntfile or am I doing something wrong?

I am using Magento 2.2.2 on Docker for Mac and running this command on my host machine. The folder /Users/admin/Sites/new/docroot is mounted to my container's root folder with the :delegated flag, if that is useful information.

Here is the content of my themes.js file:

/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

'use strict';

/**
 * Define Themes
 *
 * area: area, one of (frontend|adminhtml|doc),
 * name: theme name in format Vendor/theme-name,
 * locale: locale,
 * files: [
 * 'css/styles-m',
 * 'css/styles-l'
 * ],
 * dsl: dynamic stylesheet language (less|sass)
 *
 */
module.exports = {
    blank: {
        area: 'frontend',
        name: 'Magento/blank',
        locale: 'en_US',
        files: [
            'css/styles-m',
            'css/styles-l',
            'css/email',
            'css/email-inline'
        ],
        dsl: 'less'
    },
    luma: {
        area: 'frontend',
        name: 'Magento/luma',
        locale: 'en_US',
        files: [
            'css/styles-m',
            'css/styles-l'
        ],
        dsl: 'less'
    },
    alliance: {
        area: 'frontend',
        name: 'Udg/alliance',
        locale: 'en_GB',
        files: [
            'css/styles-m',
            'css/styles-l'
        ],
        dsl: 'less'
    },
    backend: {
        area: 'adminhtml',
        name: 'Magento/backend',
        locale: 'en_US',
        files: [
            'css/styles-old',
            'css/styles'
        ],
        dsl: 'less'
    }
};

I just tried running Grunt with --verbose option and here is the output:

$ grunt --verbose
Initializing
Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks.

/Users/admin/Sites/new/docroot/node_modules/node-minify/node_modules/babel-preset-babili/lib/index.js:32
      get() {
         ^
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token (
>>   at Module._compile (module.js:439:25)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (/Users/admin/Sites/new/docroot/node_modules/grunt/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
>>   at Function.Module._load (module.js:312:12)
>>   at Module.require (module.js:364:17)
>>   at require (module.js:380:17)
>>   at Object.<anonymous> (/Users/admin/Sites/new/docroot/node_modules/node-minify/lib/compressors/babili.js:15:25)
>>   at Module._compile (module.js:456:26)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (/Users/admin/Sites/new/docroot/node_modules/grunt/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
>>   at Function.Module._load (module.js:312:12)
>>   at Module.require (module.js:364:17)
>>   at require (module.js:380:17)
>>   at Object.<anonymous> (/Users/admin/Sites/new/docroot/node_modules/node-minify/lib/compress.js:16:14)
>>   at Module._compile (module.js:456:26)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (/Users/admin/Sites/new/docroot/node_modules/grunt/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
>>   at Function.Module._load (module.js:312:12)
>>   at Module.require (module.js:364:17)
>>   at require (module.js:380:17)
>>   at Object.<anonymous> (/Users/admin/Sites/new/docroot/node_modules/node-minify/lib/node-minify.js:15:16)
>>   at Module._compile (module.js:456:26)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (/Users/admin/Sites/new/docroot/node_modules/grunt/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
>>   at Function.Module._load (module.js:312:12)
>>   at Module.require (module.js:364:17)
>>   at require (module.js:380:17)
>>   at Object.<anonymous> (/Users/admin/Sites/new/docroot/node_modules/node-minify/index.js:9:18)
>>   at Module._compile (module.js:456:26)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (/Users/admin/Sites/new/docroot/node_modules/grunt/node_modules/coffeescript/lib/coffee-script/register.js:45:36)
>>   at Function.Module._load (module.js:312:12)
>>   at Module.require (module.js:364:17)
>>   at require (module.js:380:17)
>>   at module.exports (/Users/admin/Sites/new/docroot/dev/tools/grunt/tasks/mage-minify.js:8:23)
>>   at /Users/admin/Sites/new/docroot/Gruntfile.js:25:22
>>   at Array.forEach (native)
>>   at Object.module.exports (/Users/admin/Sites/new/docroot/Gruntfile.js:24:11)
>>   at loadTask (/Users/admin/Sites/new/docroot/node_modules/grunt/lib/grunt/task.js:315:10)
>>   at Task.task.init (/Users/admin/Sites/new/docroot/node_modules/grunt/lib/grunt/task.js:434:5)
>>   at Object.grunt.tasks (/Users/admin/Sites/new/docroot/node_modules/grunt/lib/grunt.js:111:8)
>>   at Object.module.exports [as cli] (/Users/admin/Sites/new/docroot/node_modules/grunt/lib/grunt/cli.js:27:9)
>>   at Object.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:44:20)
>>   at Module._compile (module.js:456:26)
>>   at Object.Module._extensions..js (module.js:474:10)
>>   at Module.load (module.js:356:32)
>>   at Function.Module._load (module.js:312:12)
>>   at Function.Module.runMain (module.js:497:10)
>>   at startup (node.js:119:16)
>>   at node.js:929:3

No tasks specified, running default tasks.
Running tasks: default
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

I am not very familiar with Grunt so that doesn't help me too much but it might for someone else. So apparently the Gruntfile.js is OK but it can't register my tasks for some reason?

Was it helpful?

Solution 2

I ended up completely reinstalling node and npm and the error was gone.

OTHER TIPS

make grunt-config.json file with this content in your root of Magento:

{
    "themes": "dev/tools/grunt/configs/themes"
}

PS. and you must have your theme defined in:

ROOT/dev/tools/grunt/configs/themes.js

Hope this helps, Regards

You need a newer version of nodejs. The one included in my copy of RHEL6 wasn't compatible with my Gruntfile.

I added the version from nodesource with this:

curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -

I removed the existing nodejs and grunt first, but then I went through the install with this version and ended up with grunt-cli v1.2.0, node v6.13.1, and npm v3.10.10. This worked for me.

I faced a similar issue. Running the command grunt less:[theme], even with node 9.9.0, npm 5.6.0, grunt 1.0.2, and grunt-cli 1.2.0, I was getting

>> SyntaxError: Unexpected Token :

or, using the --verbose flag:

Loading "Gruntfile.js" tasks...ERROR
>> /[path]/package.json.sample:2
>>     "name": "magento2",
>>           ^

which was obviously a valid piece of JSON. For me in particular, the hint was in the filename: package.json.sample. I had previously executed the command ln -s creating a symlink from package.json to the aforementioned .sample file, but when I instead created a full copy of the file, the error disappeared.

If I had to guess, I bet the issue arose because I'm mounting my virtual Linux filesystem into Windows, and Windows handles linked files very differently.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top