node.js 错误:找不到模块“time-grunt”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27858546/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: Cannot find module 'time-grunt'
提问by vitya-ne
I try install time-grunt local and global, clear npm cache, update npm, but nothing helps. I get:
我尝试安装 time-grunt 本地和全局,清除 npm 缓存,更新 npm,但没有任何帮助。我得到:
Loading "Gruntfile.js" tasks...ERROR
Error: Cannot find module 'time-grunt'
Warning: Task "default" not found. Use --force to continue.
My version od packages: node: '0.10.31', npm: '1.4.23'
我的版本 od 包:节点:'0.10.31',npm:'1.4.23'
After run: npm install --save-dev time-grunt in package.json state:
运行后: npm install --save-dev time-grunt in package.json 状态:
"devDependencies": {
"grunt": "^0.4.5",
...
"time-grunt": "^1.0.0"
}
This is part of my grunfile.js:
这是我的 grunfile.js 的一部分:
module.exports = function( grunt ) {
require('time-grunt')(grunt);
grunt.initConfig({
// grunt tasks here
});
// load tasks here
// register task here
}
Other grunt tasks runing without error.
其他 grunt 任务运行没有错误。
I not understand what is wrong.
我不明白出了什么问题。
How I can test correctly installation of time-grunt by command line?
如何通过命令行测试正确安装 time-grunt?
采纳答案by Shiyaz
You need to add it inside dependencies and not within devDependencies. This way you don't need to separately run $ npm install --save-dev time-grunt
您需要将它添加到依赖项中,而不是在 devDependencies 中。这样你就不需要单独运行$ npm install --save-dev time-grunt
{
"name": "grunt-build",
"version": "0.1.0",
"private": true,
"dependencies": {
"time-grunt": "^1.3.0"
},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "~0.7.0",
"grunt-contrib-compress": "~0.5.0",
"grunt-contrib-concat": "~0.5.0",
"grunt-contrib-copy": "^0.8.0",
"grunt-contrib-uglify": "~0.5.0",
"grunt-remove-logging": "~0.2.0"
}
}
回答by Prakash
use npm installor sudo npm installin the folder with package.json
使用npm install或sudo npm install在 package.json 文件夹中
回答by Martin S Ek
I ended up installing all grunt dependencies manually.
我最终手动安装了所有 grunt 依赖项。
npm install time-grunt
npm install load-grunt-config
and then all modules listed here:
然后这里列出的所有模块:


Note: you can install all of the dependencies in the photo above in one go with npm install.
注意:您可以一次性安装上图中的所有依赖项npm install。
Finally I ran the gruntcommand and it worked!
最后我运行了grunt命令并且它起作用了!

