SyntaxError:意外的令牌{在Gruntfile.js中

时间:2018-05-23 07:44:03

标签: gruntjs magento2

我无法配置 grunt 。我已经按照Magento2的所有步骤操作,但是我收到了这个语法错误。

grunt    
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected token {
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

我重新安装了grunt和node.js,但它不起作用。

有人有同样的问题吗?

您可以在下面看到Gruntfile.js(原创)张贴。

这个文件有错误还是有其他问题?

Gruntfile.js

module.exports = function (grunt) {
    'use strict';

    var _ = require('underscore'),
        path = require('path'),
        filesRouter = require('./dev/tools/grunt/tools/files-router'),
        configDir = './dev/tools/grunt/configs',
        tasks = grunt.file.expand('./dev/tools/grunt/tasks/*'),
        themes;

    filesRouter.set('themes', 'dev/tools/grunt/configs/themes');
    themes = filesRouter.get('themes');

    tasks = _.map(tasks, function(task){ return task.replace('.js', '') });
    tasks.push('time-grunt');
    tasks.forEach(function (task) {
        require(task)(grunt);
    });

    require('load-grunt-config')(grunt, {
        configPath: path.join(__dirname, configDir),
        init: true,
        jitGrunt: {
            staticMappings: {
                usebanner: 'grunt-banner'
            }
        }
    });

    _.each({
        /**
         * Assembling tasks.
         * ToDo: define default tasks.
         */
        default: function () {
            grunt.log.subhead('I\'m default task and at the moment I\'m empty, sorry :/');
        },

        /**
         * Production preparation task.
         */
        prod: function (component) {
            var tasks = [
                'less',
                'autoprefixer',
                'cssmin',
                'usebanner'
            ].map(function(task){
                return task + ':' + component;
            });

            if (typeof component === 'undefined') {
                grunt.log.subhead('Tip: Please make sure that u specify prod subtask. By default prod task do nothing');
            } else {
                grunt.task.run(tasks);
            }
        },

        /**
         * Refresh themes.
         */
        refresh: function () {
            var tasks = [
                'clean',
                'exec:all'
            ];
            _.each(themes, function(theme, name) {
                tasks.push('less:' + name);
            });
            grunt.task.run(tasks);
        },

        /**
         * Documentation
         */
        documentation: [
            'replace:documentation',
            'less:documentation',
            'styledocco:documentation',
            'usebanner:documentationCss',
            'usebanner:documentationLess',
            'usebanner:documentationHtml',
            'clean:var',
            'clean:pub'
        ],

        'legacy-build': [
            'mage-minify:legacy'
        ],

        spec: function (theme) {
            var runner = require('./dev/tests/js/jasmine/spec_runner');

            runner.init(grunt, { theme: theme });

            grunt.task.run(runner.getTasks());
        }
    }, function (task, name) {
        grunt.registerTask(name, task);
    });
};

提前致谢!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误。

我使用以下命令安装了节点,并解决了错误。

curl -sL https://deb.nodesource.com/setup_8.x | sudo bash -
sudo apt install nodejs

node -v
npm -v

希望这会有所帮助!