Reputation: 11064
I am making a basic grunt file to start my express.js server. I know there is a plugin just for that, but for learning purposes I want to do it by hand. I am getting a connect not defined message when I run grunt. However, it's defined as far as I can tell.
Error message:
one@localhost ~/app/yo $ grunt
Running "default" task
Warning: connect is not defined Use --force to continue.
Aborted due to warnings.
one@localhost ~/app/yo $
Gruntfile.js:
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
servedFiles: {
files: '<%= pkg.name %>/static/**',
options: {
livereload: true
}
},
},
connect: {
options: {
port: 8000,
hostname: '0.0.0.0',
livereload: 35729
},
},
});
grunt.registerTask('default', 'start server', function() {
grunt.task.run(connect);
});
}
Grunt modules:
one@localhost ~/app/yo $ lr node_modules/
total 68k
drwxr-xr-x 8 one users 8 Apr 26 17:54 .
drwxr-xr-x 4 one users 7 Apr 26 18:23 ..
drwxr-xr-x 2 one users 3 Apr 25 21:11 .bin
drwxr-xr-x 5 one users 13 Apr 25 21:11 express
drwxr-xr-x 5 one users 9 Apr 26 17:54 grunt
drwxr-xr-x 4 one users 7 Apr 26 17:54 grunt-contrib-connect
drwxr-xr-x 4 one users 7 Apr 26 17:54 grunt-contrib-watch
drwxr-xr-x 3 one users 6 Apr 25 21:37 load-grunt-tasks
one@localhost ~/app/yo $
Upvotes: 1
Views: 688
Reputation: 123453
The error is because connect
isn't being defined as a variable:
grunt.task.run(connect);
// ^ ReferenceError
It can be used as a one if it's declared first:
var connect = 'connect';
But, it should otherwise be a String
value that Grunt can use to find the registered task:
grunt.task.run('connect');
Upvotes: 3