Javascript 运行grunt bower会抛出u0.object不是函数错误

Javascript 运行grunt bower会抛出u0.object不是函数错误,javascript,node.js,gruntjs,lodash,Javascript,Node.js,Gruntjs,Lodash,我正在尝试运行grunt bower任务以复制我的所有bower组件 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/gr

我正在尝试运行grunt bower任务以复制我的所有bower组件

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/commands/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 _combinedTickCallback (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/commands/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 _combinedTickCallback (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/commands/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 _combinedTickCallback (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/commands/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 _combinedTickCallback (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/commands/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 _combinedTickCallback (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/commands/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 _combinedTickCallback (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.
还有我的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"
  }
}
_.object=u.zipObject

但这并不奏效


有什么想法或建议吗?

我有一段时间没有使用Grunt了,但我想我无论如何都会解决这个问题。希望这能有所帮助

调查 我查看了抛出错误的helper.js文件,发现:

然后我查看了一下,发现
Grunt.util.\u
已被弃用

然后我发现了这个回购协议:

我在那里看到这个通知:

随着Grunt的下一个主要版本的发布,我们将不再支持这些API。在可能的情况下,请使用推荐的模块。如果您希望支持或改进这些API中的任何一个,请在发布向后兼容的npm模块后通知我们,我们将在此处推荐使用

因此,看起来有一个兼容性问题:grunt bower希望
grunt.util.\uz
存在,但它在grunt的最新版本中不存在

解决方案 您可以使用grunt legacy util,也可以简单地抛出一个
grunt.util.\uz=require('lodash')
调用。这应该可以解决问题

另外,可能有人应该让grunt bower的维护人员知道他的库与grunt的当前版本不再兼容

编辑:我刚刚研究了Grunt的新版本是如何填充Grunt.util的,我看到:


所以现在我很困惑。。。Grunt的新版本仍然提供遗留的UTIL吗?如果这是真的,那么我不知道你的构建为什么会被破坏。好吧,不管怎样,希望这些信息能为你指明正确的方向。

问题在于下划线和lodash并不像有些人认为的那样配合得很好。下划线有
。.object
,lodash有
。.zipoobject

grunt.util和grunt.utils的创建者也不共享与grunt.utils.\uu和grunt.util.\uu和相同的库首选项,而这正是构建所使用的(根据堆栈跟踪)

这是grunt bower中的一个bug,假设他们显然也在尝试支持grunt.util,并且没有grunt.utils或下划线作为依赖项时存在
.object
。无论如何

解决 1.包括grunt.utlis 我在Grunt方面没有太多经验,更不用说Grunt.utlis了,但我怀疑如果您按照指南抓取包并加载它,Grunt bower应该默认为该值(即下划线)。至少从源头上看似乎是这样

2.直接添加u.object方法 我一点也不确定这是否有效,而且无论如何,它看起来非常骇人,但就像你试图做的那样

grunt.util._.object = _.zipObject
可能只是在没有其他依赖项的情况下完成这个任务。不过我建议你试试第一个

3.修复grunt bower中的错误* 打开一个问题,也许创建一个公关。无论如何,这应该只是一个小的改变,因此,如果其他两个都不起作用,即使是分拆回购似乎也是一个可靠的选择


更新 。显然它是昨天制作的,所以我打赌它很快就会合并。不过,评论部分的鼓励可能不会有什么坏处


*更新2
修复程序现在位于主分支中,可通过v0.21.1中的npm获得。我发现将“grunt bower”版本更改为最新版本(0.21.4)可以解决此错误

例如,在grunt的bower.js中-bower@0.21.4,
“uu1”定义为lodash,如下所示:

var _ = require('lodash'); 

对象的用法在哪里?如果您需要在该文件中添加新的lodash,它将使lodash重新设置为原始值。
var _ = grunt.utils ? grunt.utils._ : grunt.util._;
var util = require('grunt-legacy-util');
grunt.util = util;
grunt.util._.object = _.zipObject
var _ = require('lodash');