admin管理员组

文章数量:1335426

I am trying to run grunt-bower task for copying all my bower-ponents.

Running "bower:dev" (bower) task
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular-mocks!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular-route!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for bootstrap!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for jquery!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for lodash!

Done.

Here's how my Gruntfile.js looks

module.exports = function(grunt) {
  var _ = require("lodash");
  _.object = _.zipObject;
  grunt.initConfig({
    "bower": {
      "dev": {
        "dest": "dist/vendor/js",
        "css_dest": "dist/vendor/css",
        "fonts_dest": "dist/fonts"
      }
    }
  });

  grunt.loadNpmTasks("grunt-bower");

  grunt.registerTask("default", ["bower"]);
};

and my package.json

{
  "name": "coc-app",
  "version": "1.0.0",
  "description": "Clash of Clans Application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "private",
  "dependencies": {
    "body-parser": "^1.15.0",
    "cookie-parser": "^1.4.1",
    "express": "^4.13.4",
    "jade": "^1.11.0",
    "lodash": ">=3.0.0 <4.0.0"
  },
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-bower": "^0.21.0",
    "grunt-contrib-concat": "^1.0.1"
  }
}

I tried resetting

var _ = require("lodash");

_.object = _.zipObject;

but this did not work.

Any thoughts or suggestions?

I am trying to run grunt-bower task for copying all my bower-ponents.

Running "bower:dev" (bower) task
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular-mocks!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for angular-route!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for bootstrap!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for jquery!
TypeError: _.object is not a function
  at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/lib/helpers.js:131:14)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:63:35
  at Array.forEach (native)
  at /Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:59:21
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4040:15
  at baseForOwn (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:2573:24)
  at /Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:4009:18
  at Function.forEach (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:7634:11)
  at LodashWrapper.object.(anonymous function) [as each] (/Users/wonoh/cocApp/node_modules/grunt-legacy-util/node_modules/lodash/lodash.js:13501:25)
  at Logger.<anonymous> (/Users/wonoh/cocApp/node_modules/grunt-bower/tasks/bower.js:37:17)
  at emitOne (events.js:90:13)
  at Logger.emit (events.js:182:7)
  at Logger.emit (/Users/wonoh/cocApp/node_modules/bower-logger/lib/Logger.js:29:39)
  at /Users/wonoh/cocApp/node_modules/bower/lib/mands/list.js:75:16
  at _fulfilled (/Users/wonoh/cocApp/node_modules/q/q.js:798:54)
  at self.promiseDispatch.done (/Users/wonoh/cocApp/node_modules/q/q.js:827:30)
  at Promise.promise.promiseDispatch (/Users/wonoh/cocApp/node_modules/q/q.js:760:13)
  at /Users/wonoh/cocApp/node_modules/q/q.js:574:44
  at flush (/Users/wonoh/cocApp/node_modules/q/q.js:108:17)
  at _binedTickCallback (internal/process/next_tick.js:67:7)
  at process._tickCallback (internal/process/next_tick.js:98:9)
Fail to copy lib file for lodash!

Done.

Here's how my Gruntfile.js looks

module.exports = function(grunt) {
  var _ = require("lodash");
  _.object = _.zipObject;
  grunt.initConfig({
    "bower": {
      "dev": {
        "dest": "dist/vendor/js",
        "css_dest": "dist/vendor/css",
        "fonts_dest": "dist/fonts"
      }
    }
  });

  grunt.loadNpmTasks("grunt-bower");

  grunt.registerTask("default", ["bower"]);
};

and my package.json

{
  "name": "coc-app",
  "version": "1.0.0",
  "description": "Clash of Clans Application",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "private",
  "dependencies": {
    "body-parser": "^1.15.0",
    "cookie-parser": "^1.4.1",
    "express": "^4.13.4",
    "jade": "^1.11.0",
    "lodash": ">=3.0.0 <4.0.0"
  },
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-bower": "^0.21.0",
    "grunt-contrib-concat": "^1.0.1"
  }
}

I tried resetting

var _ = require("lodash");

_.object = _.zipObject;

but this did not work.

Any thoughts or suggestions?

Share Improve this question asked Apr 24, 2016 at 2:53 Won OhWon Oh 3361 silver badge9 bronze badges 1
  • where is the _.object usage? if you are requiring a new lodash in that file, it will have lodash re-set to the original value. – Catalyst Commented Apr 24, 2016 at 4:15
Add a ment  | 

3 Answers 3

Reset to default 8 +50

The problem es from the fact that Underscore and lodash don't play as well together as some might think they do. Underscore has _.object, lodash has _.zipObject.

The creators of grunt.util and grunt.utils don't share the same library preferences either, as grunt.utils._ is a reference to Underscore and grunt.util._ is a reference to lodash and so is grunt-legacy-util._, which is what your build is using (according to the stack trace).

That's a bug in grunt-bower, assuming there is _.object when they are clearly trying to support grunt.util._ too and don't have grunt.utils or Underscore as a dependency. Anyways...

Solutions

1. Include grunt.utlis

I don't have much experience on Grunt, much less grunt.utlis, but I suspect that if you grab the grunt-utils package and load it like they guide, grunt-bower should just default to that (and namely, Underscore) instead. At least looking at the source it seems so.

2. Add the _.object method directly

I'm not sure at all if this would work and in any case it seems super hacky, but much like you were trying to do,

grunt.util._.object = _.zipObject

might just do the trick without other dependencies to project. I suggest you try the first one though.

3. Fix the bug in grunt-bower *

Open an issue, maybe create a PR. It should be just a small change to one file anyways, so even forking the repo seems like a solid option if the other two won't work.


Update

There already is an open PR about this that I didn't notice before. Apparently it was made yesterday, so I bet it will get a merge in no time. Little encouragement in the ments section might not hurt though.


*Update 2

The fix is now in the master branch and available through npm in v0.21.1

I haven't used Grunt in a while but I figured I would tackle this one anyway. Hopefully this helps.

The investigation

I took a look in the helper.js file that's throwing the error, and I found this line:

var _ = grunt.utils ? grunt.utils._ : grunt.util._;

Then I took a look in the Grunt docs for Grunt.util and saw that Grunt.util._ was deprecated.

Then I found this repo:

https://github./gruntjs/grunt-legacy-util

where I saw this notice:

With the next major release of Grunt, we will no longer support these APIs. Where possible, please use the remended modules in their place. If you would like to support or improve any of these APIs, please notify us when you have published a backwards patible npm module—we will then remend its usage here.

So it looks like there's a patibility issue: grunt-bower expects grunt.util._ to exist, but it doesn't exist in the newest version of Grunt.

The solution

You can either use grunt-legacy-util or simply throw in a grunt.util._ = require('lodash') call. That should fix the issue.

Also, someone should probably let the maintainer of grunt-bower know that his library is no longer patible with the current version of Grunt.

Edit: I just looked into how the new version of Grunt populates grunt.util and I saw this:

var util = require('grunt-legacy-util');
grunt.util = util;

So now I'm confused... is the new version of Grunt still providing the legacy utils? If that's true, then I'm not sure why your build is broken. Well, either way, hope some of this info points you in the right direction.

I found changing 'grunt-bower' version into newest(0.21.4) can solve this error.

In detail, for example, in bower.js of [email protected],
'_' is defined as lodash, like this:

var _ = require('lodash'); 

本文标签: javascriptRunning gruntbower throws object is not a function errorStack Overflow