我正在尝试运行 grunt-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.
这是我的 Gruntfile.js 的外观
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"]);
};
还有我的 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"
}
}
我试过重置
var _ = require("lodash");
_.object = _.zipObject;
但这不起作用。
有什么想法或建议吗?
最佳答案
问题在于,Underscore 和 lodash 不能像某些人认为的那样很好地协同工作。下划线有_.object
,lodash有_.zipObject
。
grunt.util 和 grunt.utils 的创建者也不共享相同的库首选项,如 grunt.utils。_ is a reference to Underscore和 grunt.util._ is a reference to lodash和 so is grunt-legacy-util._ ,这是您的构建正在使用的(根据堆栈跟踪)。
这是 grunt-bower 中的一个错误,假设有 _.object
当他们显然也试图支持 grunt.util._ 并且没有 grunt.utils 或 Underscore 作为依赖项.总之……
解决方案
1。包括 grunt.utlis
我没有太多关于 Grunt 的经验,更不用说 grunt.utlis,但我怀疑如果你捕获 grunt-utils像他们指导的那样打包并加载它,grunt-bower 应该默认为那个(即下划线)。至少从源头上看是这样的。
2。直接添加_.object方法
我完全不确定这是否可行,无论如何它看起来 super hacky,但就像你试图做的那样,
grunt.util._.object = _.zipObject
可能只是在没有其他依赖项的情况下完成这个技巧。不过我建议你尝试第一个。
3。 修复 grunt-bower *中的错误
打开一个问题,也许创建一个 PR。应该只是个小改动to one file无论如何,如果其他两个不起作用,即使 fork repo 似乎也是一个不错的选择。
更新
There already is an open PR about this that I didn't notice before .显然它是昨天制作的,所以我敢打赌它很快就会被合并。不过,评论部分的小鼓励可能不会受到伤害。
*更新 2
修复程序现在位于主分支中,可通过 v0.21.1
中的 npm 获得关于javascript - 运行 grunt-bower 抛出 _.object 不是函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36818787/