firstandthird / load-grunt-config

Grunt plugin that lets you break up your Gruntfile config by task
firstandthird.github.io/load-grunt-config/
MIT License
374 stars 64 forks source link

Cannot add new tasks or rename existing tasks #174

Closed andyexeter closed 6 years ago

andyexeter commented 6 years ago

Bit of a strange one...I have a task defined in grunt/webpack.js but when I try to run grunt webpack I get:

$ grunt webpack
Warning: Task "webpack" not found. Use --force to continue.
Error: Task "webpack" not found.
    at Task.run (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/util/task.js:172:28)
    at /home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt.js:152:39
    at Array.forEach (native)
    at Object.grunt.tasks (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt.js:152:9)
    at Object.module.exports [as cli] (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt/cli.js:27:9)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/grunt-cli/bin/grunt:44:20)
    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.runMain (module.js:604:10)
    at run (bootstrap_node.js:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496:3

Aborted due to warnings.

I have a number of other tasks in the same directory e.g grunt/uglify.js, which runs just fine:

$ grunt uglify
Running "uglify:dist" (uglify) task
>> 1 file created 4.56 kB → 1.57 kB

Done.

To try and debug this, I renamed grunt/uglify.js to grunt/uglif.js and it stopped working...

$ grunt uglif
Warning: Task "uglif" not found. Use --force to continue.
Error: Task "uglif" not found.
    at Task.run (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/util/task.js:172:28)
    at /home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt.js:152:39
    at Array.forEach (native)
    at Object.grunt.tasks (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt.js:152:9)
    at Object.module.exports [as cli] (/home/andy/projects/jquery-grouprequired/node_modules/grunt/lib/grunt/cli.js:27:9)
    at Object.<anonymous> (/usr/local/share/.config/yarn/global/node_modules/grunt-cli/bin/grunt:44:20)
    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.runMain (module.js:604:10)
    at run (bootstrap_node.js:383:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:496:3

Aborted due to warnings.

The output of grunt --config-debug is:

CONFIG:
==============================
{
  "aliases": {
    "default": [
      "jshint:src",
      "jscs:src",
      "dist",
      "readme"
    ],
    "dist": [
      "includes:dist",
      "uglify:dist",
      "jshint:dist",
      "jscs:dist"
    ],
    "test": [
      "browserify",
      "webpack",
      "qunit"
    ]
  },
  "browserify": {
    "build": {
      "src": "src/test/unit/browserify.js",
      "dest": "test/unit/browserify.js"
    }
  },
  "includes": {
    "dist": {
      "options": {
        "includeRegexp": {},
        "banner": "/**\n * <%= pkg.name %> v<%= pkg.version %>\n *\n * @author <%= pkg.author %>\n * @license <%= pkg.license %>\n */\n"
      },
      "src": "<%= files.boilerplate %>",
      "dest": "<%= files.main %>"
    }
  },
  "jscs": {
    "options": {
      "config": ".jscsrc"
    },
    "src": {
      "src": "src/**/*.js"
    },
    "dist": {
      "src": "<%= files.main %>"
    },
    "grunt": {
      "src": "Gruntfile.js"
    }
  },
  "jshint": {
    "options": {
      "jshintrc": ".jshintrc"
    },
    "src": {
      "src": "src/**/*.js"
    },
    "dist": {
      "src": "<%= files.main %>"
    },
    "grunt": {
      "options": {
        "node": true
      },
      "src": "Gruntfile.js"
    }
  },
  "qunit": {
    "dist": {
      "options": {
        "page": {
          "viewportSize": {
            "height": 966
          }
        }
      },
      "src": "test/index.html"
    }
  },
  "readme": {},
  "uglify": {
    "dist": {
      "options": {
        "sourceMap": false,
        "report": "gzip",
        "preserveComments": {}
      },
      "src": "<%= files.main %>",
      "dest": "<%= files.min %>"
    }
  },
  "watch": {
    "js": {
      "files": [
        "src/**/*.js"
      ],
      "tasks": [
        "jshint:dist",
        "includes:dist",
        "uglify:dist"
      ]
    }
  },
  "webpack": {
    "blah": {
      "entry": "./src/test/unit/webpack.js",
      "mode": "development",
      "output": {
        "path": "/home/andy/projects/jquery-grouprequired/test/unit",
        "filename": "webpack.js"
      }
    }
  }
}

ALIASES:
==============================
default ["jshint:src","jscs:src","dist","readme"]
dist ["includes:dist","uglify:dist","jshint:dist","jscs:dist"]
test ["browserify","webpack","qunit"]

So the webpack task is clearly being picked up when the config is generated. Any idea what's going on here? My Travis CI builds are failing with the same issue so I think that rules out any quirks from my machine.

andyexeter commented 6 years ago

Closing this because it was caused by user error. I hadn't included the grunt-webpack module in my package.json and forgot that tasks have to match the names of the grunt modules, hence grunt uglif not working!