Node.js 无法让grunt运行任何任务
很抱歉,这是新的。 我正在运行node.jsv6.9.5npm4.2.0。 已在Windows 10上安装grunt cli 这就是我认为我出错的地方,我安装了npm-g grunt init,它在C:\User[my name]\AppDate\Roaming目录中创建了一个node\u modules文件夹 此后,我使用Node.js 无法让grunt运行任何任务,node.js,npm,gruntjs,Node.js,Npm,Gruntjs,很抱歉,这是新的。 我正在运行node.jsv6.9.5npm4.2.0。 已在Windows 10上安装grunt cli 这就是我认为我出错的地方,我安装了npm-g grunt init,它在C:\User[my name]\AppDate\Roaming目录中创建了一个node\u modules文件夹 此后,我使用npm uninstall grunt--save卸载了此文件 我在项目根目录中创建了以下package.jason: { "name": "manifest", "
npm uninstall grunt--save
卸载了此文件
我在项目根目录中创建了以下package.jason:
{
"name": "manifest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {},
"devDependencies": {
"grunt": "^1.0.1"
}
}
运行npm install,它在我的项目根目录中创建了一个新的node_modules目录
创建包含以下内容的Gruntfile.js:
module.exports = function(grunt) {
grunt.registerTask('speak', function() {
console.log('hello');
})
}
但是当我运行grunt speak
时,我得到的信息是:
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Invalid or unexpected token
Warning: Task "speak" not found. Use --force to continue.
Aborted due to warnings.
请问我做错了什么?好的,通过完全卸载grunt、grunt cli、npm和node.js,并从头开始重新安装,设法解决了这个问题。
grunt
的注册任务方法有构造函数(任务名称、描述、任务函数)
,所以,也许你也应该添加任务的描述,以使其工作?编辑:没关系,我错了。找到源代码,如果description为null,则将函数作为第二个参数。