Javascript Grunt-警告:未找到任务“默认值”。使用--force继续
刚开始尝试设置Grunt,但马上遇到了一个问题Javascript Grunt-警告:未找到任务“默认值”。使用--force继续,javascript,node.js,gruntjs,Javascript,Node.js,Gruntjs,刚开始尝试设置Grunt,但马上遇到了一个问题 Warning: Task "default" not found. Use --force to continue. 或全部: >> Error: Unable to parse "package.json" file (Unexpected token c). Warning: Task "default" not found. Use --force to continue. Aborted due to warnings.
Warning: Task "default" not found. Use --force to continue.
或全部:
>> Error: Unable to parse "package.json" file (Unexpected token c).
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
我遵循以下指南:
这两个文件是:
package.json:
{
"name": "BuildSanctuary",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "^0.5.0"
}
}
Grunfile.js
module.exports = function(grunt) {
// 1. All configuration goes here
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
dist: {
src: [
'public_html/js/*.js', // All JS in the libs folder
],
dest: 'public_html/js/production.js',
}
}
});
// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat']);
};
为了解决这个问题,我将文件保存为UTF-8,它工作正常。将文件保存为UTF-8将有所帮助。 在我的例子中,只需转到文本编辑器,它是崇高的文本 文件->编码保存->UTF-8
grunt能够找到默认任务。我可以通过安装grunt cli来解决这个问题,我只安装了grunt,并且遇到了相同的错误
npm install --save-dev grunt-cli
编辑:
以上这些让我更接近这个问题。我遇到了其他丢失的软件包。一旦我把它们全部安装好,它就工作了。我毫不怀疑它与您上面粘贴的代码编码有关!错误显示意外的标记c。一定是字符串外的某个地方有字符c,或者整个文件中完全没有JSON。我四处搜索,发现其他人也有同样的问题。其他地方有人建议将文件保存为UTF-8,因为标准编码增加了一些额外的内容。。。如果我诚实的话,那就超出我的范围了。但是更改存储类型修复了它。它以前是什么编码?这对你回答其他有同样问题的人会很有帮助