节点Grunt.js'警告:连接未定义使用'

我正在做一个基本的grunt文件来启动我的express.js服务器。 我知道这是一个插件,但为了学习的目的,我想用手工做。 当我运行grunt时,我得到一个连接未定义的消息。 但是,据我所知,它被定义。

错误信息:

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模块:

 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 $ 

错误是因为connect没有被定义为一个variables:

 grunt.task.run(connect); // ^ ReferenceError 

如果首先声明它可以用作一个:

 var connect = 'connect'; 

但是,它应该是一个Grunt可以用来查找注册任务的String值:

 grunt.task.run('connect');