0

我有一个带有一些旧代码的 Sails.js 应用程序。该应用程序的原始开发人员遵循这个Stackoverflow 答案来组织 grunt 任务及其目录结构。但是,对于 Grunt ^1.0.4,Gruntfile.js 在构建时会抛出以下错误:

Loading "Gruntfile.js" tasks...ERROR
>> TypeError: tasks[taskName] is not a function

我正在使用 yarn 来构建 Sails.js 项目以及:

yarn && grunt buildProd && pm2 start production.config.js

知道如何解决这个问题吗?我是否需要废弃此代码并根据路径手动加载每个任务?任何帮助将不胜感激!

Gruntfile.js:

/**
 * Gruntfile
 *
 * This Node script is executed when you run `grunt` or `sails lift`.
 * It's purpose is to load the Grunt tasks in your project's `tasks`
 * folder, and allow you to add and remove tasks as you see fit.
 * For more information on how this works, check out the `README.md`
 * file that was generated in your `tasks` folder.
 *
 * WARNING:
 * Unless you know what you're doing, you shouldn't change this file.
 * Check out the `tasks` directory instead.
 */

module.exports = function(grunt) {

    // Load the include-all library in order to require all of our grunt
    // configurations and task registrations dynamically.
    var includeAll;
    try {
        includeAll = require('include-all');
    } catch (e0) {
        try {
            includeAll = require('sails/node_modules/include-all');
        }
        catch(e1) {
            console.error('Could not find `include-all` module.');
            console.error('Skipping grunt tasks...');
            console.error('To fix this, please run:');
            console.error('npm install include-all --save`');
            console.error();

            grunt.registerTask('default', []);
            return;
        }
    }

    /**
     * Loads Grunt configuration modules from the specified
     * relative path. These modules should export a function
     * that, when run, should either load/configure or register
     * a Grunt task.
     */
    function loadTasks(relPath) {
        return includeAll({
            dirname: require('path').resolve(__dirname, relPath),
            filter: /(.+)\.js$/
        }) || {};
    }

    /**
     * Invokes the function from a Grunt configuration module with
     * a single argument - the `grunt` object.
     */
    function invokeConfigFn(tasks) {
        for (var taskName in tasks) {
            if (tasks.hasOwnProperty(taskName)) {
                tasks[taskName](grunt);
            }
        }
    }

    // Load task functions
    var taskConfigurations = loadTasks('./tasks/config'),
        registerDefinitions = loadTasks('./tasks/register');

    // (ensure that a default task exists)
    if (!registerDefinitions.default) {
        registerDefinitions.default = function (grunt) { grunt.registerTask('default', []); };
    }

    // Run task functions to configure Grunt.
    invokeConfigFn(taskConfigurations);
    invokeConfigFn(registerDefinitions);

};

包.json:

"dependencies": {
    "angular": "^1.7.8",
    "angular-google-maps": "^2.4.1",
    "angular-multiple-select": "^1.1.3",
    "async": "^2.6.2",
    "aws-sdk": "^2.441.0",
    "bluebird": "^3.5.4",
    "blueimp-md5": "^2.10.0",
    "bootstrap-select": "^1.13.10",
    "browserify": "^16.2.3",
    "buffer-equal-constant-time": "^1.0.1",
    "csv": "^5.1.1",
    "ejs": "^2.6.1",
    "grunt": "^1.0.4",
    "grunt-cli": "1.2.0",
    "grunt-contrib-clean": "^2.0.0",
    "grunt-contrib-concat": "~1.0.1",
    "grunt-contrib-copy": "~1.0.0",
    "grunt-contrib-cssmin": "~3.0.0",
    "grunt-contrib-less": "2.0.0",
    "grunt-contrib-uglify": "3.3.0",
    "grunt-contrib-watch": "~1.1.0",
    "grunt-sails-linker": "~1.0.4",
    "grunt-sync": "~0.8.0",
    "include-all": "^4.0.3",
    "is-my-json-valid": "^2.19.0",
    "jsforce": "^1.9.1",
    "jsonwebtoken": "^8.5.1",
    "level": "^5.0.1",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "moment-timezone": "^0.5.25",
    "mysql": "^2.17.1",
    "nested-pop": "^0.1.4",
    "ngmap": "^1.18.5",
    "node-where": "^1.1.0",
    "nodemailer": "^6.1.1",
    "passport": "^0.4.0",
    "passport-http-bearer": "^1.0.1",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "q": "^1.5.1",
    "qr-image": "^3.2.0",
    "randomstring": "^1.1.5",
    "rc": "^1.2.8",
    "robots.txt": "^1.1.0",
    "s3-streaming-upload": "^0.2.3",
    "sails": "^1.1.0",
    "sails-mysql": "^1.0.1",
    "skipper-s3": "^0.6.0",
    "sms-global-js": "^1.0.0",
    "stream-mmmagic": "^2.1.0",
    "stripe": "^6.30.0",
    "uuid": "^3.3.2",
    "winston": "^3.2.1",
    "winston-logentries": "^3.0.0"
  },
4

0 回答 0