2013-10-02 7 views
16

otrzymuję ten dziwny błąd podczas próby uruchomienia chrząknięcie: TypeError: Object Gruntfile.js has no method 'flatten'Pierwsze dziwny błąd z chrząknięcie: Przedmiot Gruntfile.js ma metodę „spłaszczyć”

Jestem nowy node.js, npm, grunt, itp. Myślałem, że zrobiłem przyzwoitą instalację węzła, npm, chrząknięcie, ale może być coś przegapiłem. Czy istnieje sposób weryfikacji instalacji?

$ 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) 

Linia wykraczająca/file:

/* 
* findup-sync 
* https://github.com/cowboy/node-findup-sync 
* 
* Copyright (c) 2013 "Cowboy" Ben Alman 
* Licensed under the MIT license. 
*/ 

'use strict'; 

// Nodejs libs. 
var path = require('path'); 

// External libs. 
var glob = require('glob'); 
var _ = require('lodash'); 

// Search for a filename in the given directory or all parent directories. 
module.exports = function(patterns, options) { 
    // Normalize patterns to an array. 
    if (!Array.isArray(patterns)) { patterns = [patterns]; } 
    // Create globOptions so that it can be modified without mutating the 
    // original object. 
    var globOptions = Object.create(options || {}); 
    globOptions.maxDepth = 1; 
    globOptions.cwd = path.resolve(globOptions.cwd || '.'); 

    var files, lastpath; 
    do { 
    // Search for files matching patterns. 
    files = _(patterns).map(function(pattern) { 
     return glob.sync(pattern, globOptions); 
    }).flatten().uniq().value(); // <--------- OFFENDING LINE 
    // Return file if found. 
    if (files.length > 0) { 
     return path.resolve(path.join(globOptions.cwd, files[0])); 
    } 
    // Go up a directory. 
    lastpath = globOptions.cwd; 
    globOptions.cwd = path.resolve(globOptions.cwd, '..'); 
    // If parentpath is the same as basedir, we can't go any higher. 
    } while (globOptions.cwd !== lastpath); 

    // No files were found! 
    return null; 
}; 

Wyjście ls -l node_modules/:

$ ls -l node_modules/ 
total 20 
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt 
drwxrwxr-x. 4 a a 4096 Oct 2 00:42 grunt-contrib-compass 
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt-contrib-jshint 
drwxrwxr-x. 6 a a 4096 Oct 2 00:42 grunt-contrib-watch 
drwxrwxr-x. 4 a a 4096 Oct 2 00:42 grunt-dustjs 

Wyjście npm list:

$ npm list 
[email protected] /home/a/prep/main/web/client 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├─┬ [email protected] 
│ │ │ ├── [email protected] 
│ │ │ └── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ └─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └─┬ [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ ├── [email protected] 
│ │ └── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├─┬ [email protected] 
│ ├─┬ [email protected] 
│ │ └─┬ [email protected] 
│ │ ├─┬ [email protected] 
│ │ │ ├── [email protected] 
│ │ │ └── [email protected] 
│ │ ├── [email protected] 
│ │ └─┬ [email protected] 
│ │  ├── [email protected] 
│ │  └── [email protected] 
│ └─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ ├─┬ [email protected] 
│ │ └─┬ [email protected] 
│ │ └── [email protected] 
│ └── [email protected] 
└─┬ [email protected] 
    └── [email protected] 

Wyjście 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" 
    } 
} 

Wyjście cat Gruntfile.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']); 
}; 
+0

Czy możesz dodawać całą zawartość tej linii naruszającego (findup-sync.js: 33) – ksimons

+0

@ksimons podziękowania dla następujących to. zamieściłem obrażającą się linię + inne informacje, które mogą być przydatne – necromancer

+0

@ksimons trochę więcej informacji: gruntfile.js i package.json – necromancer

Odpowiedz

9

Jak zostało napisane w https://github.com/gruntjs/grunt/issues/888dist w .gitignore

nadzieję, że pomoże

+0

+1 dziękuję, to wydaje się być poprawna odpowiedź – necromancer

+0

Aby wyjaśnić: nie po prostu umieść 'dist' w twoim .gitignore. Umieść coś tak konkretnego, jak tego potrzebujesz. Dla mnie było to './Dist /' –

2

To wygląda jak jeden z twoich modułów Grunt próbuje użyć underscore.js ale nie jest zainstalowany. To powinno rozwiązać problem:

npm install underscore 

Albo jeszcze lepiej, dodać podkreślenia jako zależność rozwoju w swojej package.json:

{ 
    <your existing stuff here> 
    "devDependencies": { 
    "underscore": "~1.5.2" 
    } 
} 
+0

to nie pomogło, ale +1 i tak – necromancer

+0

Spróbuj zainstalować go globalnie z: npm install -g underscore – ksimons

+0

@ksmimons też nie działa. – necromancer

19

Spróbuj ponownie zainstalować moduły węzła.

  1. Usuń folder node_modules
  2. Czy npm cache clean
  3. Wykonaj npm install

Nadzieja to pomaga :)

+0

rm -rf node_modules && npm cache clean && npm i –

Powiązane problemy