Node.JS / Grunt-Nodemon: ReferenceError: mode is not defined

Node.JS / Grunt-Nodemon: ReferenceError: mode is not defined

我目前正在学习 Node.JS 并希望通过 Grunt 提高我的开发速度。我已经在全球范围内安装了 "grunt-cli",并通过 NPM 在本地安装了 "grunt-nodemon" 作为开发资源。目标是 Node.JS 重新启动,每当 JavaScript 文件更改时。

这是我在控制台中得到的:

D:\Projects\NodeJS\Web\Board\>grunt
Loading "gruntfile.js" tasks...ERROR
>> ReferenceError: mode is not defined
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

这是我的 gruntfile.js:

//gruntfile.js
mode.exports = function (grunt) {
    grunt.initConfig({
        nodemon: {
            all: {
                script: 'server.js',
                options: {
                    watchedExtensions: ['js']
                }
            }
        },      
    });
    grunt.loadNpmTasks('grunt-nodemon');
    grunt.registerTask('default', ['nodemon']);
}; 

控制台指向与 gruntfile.js 相同的目录。

如果你有任何想法,请告诉我。谢谢!

您的代码的第 1 行是

mode.exports

应该是

module.exports   // change mode to module. Its a typo in your code

因此出现错误

ReferenceError: mode is not defined

检查错别字。快乐的编码。