Javascript grunt出现奇怪错误:对象GrunFile.js没有方法';展平';
我在尝试运行grunt时遇到了一个奇怪的错误:Javascript grunt出现奇怪错误:对象GrunFile.js没有方法';展平';,javascript,node.js,npm,gruntjs,Javascript,Node.js,Npm,Gruntjs,我在尝试运行grunt时遇到了一个奇怪的错误:TypeError:Object Gruntfile.js没有方法“展平” 我对node.js、npm、grunt等都是新手。我以为我安装了node、npm、grunt,但可能我错过了什么。是否有方法验证安装 $ cat xx $ grunt /home/cl/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33 }).flatten().uniq().value
TypeError:Object Gruntfile.js没有方法“展平”
我对node.js、npm、grunt等都是新手。我以为我安装了node、npm、grunt,但可能我错过了什么。是否有方法验证安装
$ cat xx
$ grunt
/home/cl/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33
}).flatten().uniq().value();
^
TypeError: Object Gruntfile.js has no method 'flatten'
at Object.module.exports [as findup] (/home/cl/node_modules/grunt/node_modules/findup-sync/lib/findup-sync.js:33:8)
at Task.task.init (/home/cl/node_modules/grunt/lib/grunt/task.js:414:16)
at Object.grunt.tasks (/home/cl/node_modules/grunt/lib/grunt.js:113:8)
at Object.module.exports [as cli] (/home/cl/node_modules/grunt/lib/grunt/cli.js:38:9)
at Object.<anonymous> (/usr/lib/node_modules/grunt-cli/bin/grunt:41:20)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
npm列表的输出
:
$ npm list
prepscholar@0.0.0 /home/a/prep/main/web/client
├─┬ grunt@0.4.1
│ ├── async@0.1.22
│ ├── coffee-script@1.3.3
│ ├── colors@0.6.2
│ ├── dateformat@1.0.2-1.2.3
│ ├── eventemitter2@0.4.13
│ ├─┬ findup-sync@0.1.2
│ │ └── lodash@1.0.1
│ ├─┬ glob@3.1.21
│ │ ├── graceful-fs@1.2.3
│ │ └── inherits@1.0.0
│ ├── hooker@0.2.3
│ ├── iconv-lite@0.2.11
│ ├─┬ js-yaml@2.0.5
│ │ ├─┬ argparse@0.1.15
│ │ │ ├── underscore@1.4.4
│ │ │ └── underscore.string@2.3.3
│ │ └── esprima@1.0.4
│ ├── lodash@0.9.2
│ ├─┬ minimatch@0.2.12
│ │ ├── lru-cache@2.3.1
│ │ └── sigmund@1.0.0
│ ├─┬ nopt@1.0.10
│ │ └── abbrev@1.0.4
│ ├─┬ rimraf@2.0.3
│ │ └── graceful-fs@1.1.14
│ ├── underscore.string@2.2.1
│ └── which@1.0.5
├─┬ grunt-contrib-compass@0.5.0
│ ├── async@0.2.9
│ ├── dargs@0.1.0
│ └── tmp@0.0.21
├─┬ grunt-contrib-jshint@0.6.4
│ └─┬ jshint@2.1.10
│ ├─┬ cli@0.4.5
│ │ └─┬ glob@3.2.6
│ │ └── inherits@2.0.1
│ ├── console-browserify@0.1.6
│ ├─┬ minimatch@0.2.12
│ │ ├── lru-cache@2.3.1
│ │ └── sigmund@1.0.0
│ ├── shelljs@0.1.4
│ └── underscore@1.4.4
├─┬ grunt-contrib-watch@0.5.3
│ ├─┬ gaze@0.4.2
│ │ └─┬ globule@0.1.0
│ │ ├─┬ glob@3.1.21
│ │ │ ├── graceful-fs@1.2.3
│ │ │ └── inherits@1.0.0
│ │ ├── lodash@1.0.1
│ │ └─┬ minimatch@0.2.12
│ │ ├── lru-cache@2.3.1
│ │ └── sigmund@1.0.0
│ └─┬ tiny-lr@0.0.4
│ ├── debug@0.7.2
│ ├── faye-websocket@0.4.4
│ ├─┬ noptify@0.0.3
│ │ └─┬ nopt@2.0.0
│ │ └── abbrev@1.0.4
│ └── qs@0.5.6
└─┬ grunt-dustjs@1.1.1
└── dustjs-linkedin@2.0.3
cat package.json的输出:
$ cat package.json
{
"name": "prepscholar",
"version": "0.0.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.6.4",
"grunt-dustjs": "~1.1.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0"
}
}
cat grunfile.js的输出
:
$ cat Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', 'app/js/**/*.js', '!app/js/lib/**/*.js']
},
dustjs: {
compile: {
src: ['app/templates/**/*.html'],
dest: 'app/js/templates.js'
}
},
compass: {
dev: {
options: {
sassDir: 'app/sass',
cssDir: 'app/css',
imagesDir: 'app/img',
fontsDir: 'app/fonts',
javascriptsDir: 'app/js/app',
outputStyle: 'compressed'
}
}
},
watch: {
gruntfile: {
files: 'Gruntfile.js',
tasks: ['compile']
},
css: {
files: 'app/sass/**/*.scss',
tasks: ['compass:dev']
},
livereload: {
options: { livereload: true },
files: ['app/css/**/*']
},
dust: {
files: 'app/templates/**/*.html',
tasks: ['dustjs']
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-dustjs');
grunt.loadNpmTasks('underscore');
grunt.registerTask('default', ['compile', 'watch']);
grunt.registerTask('compile', ['dust', 'compass']);
grunt.registerTask('dust', ['dustjs']);
grunt.registerTask('lint', ['jshint']);
};
看起来您的grunt模块之一正在尝试使用,但尚未安装。这将解决您的问题:
npm install underscore
或者更好的是,在package.json中添加下划线作为开发依赖项:
{
<your existing stuff here>
"devDependencies": {
"underscore": "~1.5.2"
}
}
{
“依赖性”:{
“下划线”:“~1.5.2”
}
}
尝试重新安装节点模块
希望能有所帮助:)发现此方法有效,如 这也应该有效。正如在.gitignore中的
dist
中所写
希望这有帮助它没有帮助,但无论如何+1尝试用:npm install-g下划线eah全局安装它,我猜错了。尝试:npm安装lodash。Lodash是下划线的替代品。我以root用户身份登录并安装了
npm安装-g Lodash
(2.2.0),但它仍然无法工作。之后,作为普通用户尝试了npm安装lodash
,但仍然存在完全相同的问题。谢谢你的持续建议。你能不能把那句冒犯性的话的全部内容发出去(findup sync.js:33)@ksimons谢谢你这么做。我已经发布了令人不快的信息+其他可能被忽略的信息useful@ksimons更多信息:gruntfile.js和package.json您需要执行的操作:npm安装lodash@ksimons在npm安装后仍然存在相同的错误-g lodash
作为rootThank you-当所有其他答案都没有时,它对我有效。澄清一下:不要只放dist
在你的.git中忽略。把你需要的东西具体化。对我来说,这是/dist/
rm-rf节点\ U模块和&npm缓存清理和&npm i
npm install underscore
{
<your existing stuff here>
"devDependencies": {
"underscore": "~1.5.2"
}
}
rm -rf node_modules/grunt
npm install grunt