【问题标题】:Grunt error: Cannot find module 'time-grunt'Grunt 错误:找不到模块“time-grunt”
【发布时间】:2015-03-07 15:43:12
【问题描述】:

我尝试安装 time-grunt local 和 global,清除 npm 缓存,更新 npm,但没有任何帮助。 我明白了:

 Loading "Gruntfile.js" tasks...ERROR
 Error: Cannot find module 'time-grunt'
 Warning: Task "default" not found. Use --force to continue.

我的软件包版本: 节点:'0.10.31', npm: '1.4.23'

运行后: npm install --save-dev time-grunt 在 package.json 状态:

"devDependencies": {
"grunt": "^0.4.5",
...
"time-grunt": "^1.0.0"
}

这是我的 grunfile.js 的一部分:

module.exports = function( grunt ) {
     require('time-grunt')(grunt);
 
     grunt.initConfig({
     // grunt tasks here
     });
     // load tasks here
     // register task here
}

其他 grunt 任务运行时没有错误。

我不明白出了什么问题。

如何通过 CLI 测试 time-grunt 的正确安装?

【问题讨论】:

  • 您能否向我们展示 Gruntfile.js 以确保您确实需要模块等
  • 这是我的 grunfile.js 的一部分: module.exports = function( grunt ) { require('time-grunt')(grunt); grunt.initConfig({ .. }); ... }
  • 似乎节点模块没有被正确查找或 grunt-time 没有正确安装。有了可用的信息,我无能为力
  • 安装 grun-time 后,我在项目子文件夹 node_modules 中有新文件夹“time-grunt”。粉丝请注意我的问题)
  • 如何通过命令行正确测试 time-grunt 的安装?

标签: node.js gruntjs npm


【解决方案1】:

我最终手动安装了所有 grunt 依赖项。

npm install time-grunt
npm install load-grunt-config

然后是这里列出的所有模块:

注意:您可以使用npm install 一次性安装上图中的所有依赖项。

最后我运行了grunt 命令并且成功了!

【讨论】:

  • 仍然收到关于找不到模块的错误
【解决方案2】:

在 package.json 文件夹中使用 npm installsudo npm install

【讨论】:

    【解决方案3】:

    您需要将其添加到依赖项中,而不是 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"
      }
    }
    

    【讨论】:

    • 希亚兹,你说得对!现在 time-grunt 工作!
    猜你喜欢
    • 2016-04-30
    • 2015-04-07
    • 2013-11-22
    • 1970-01-01
    • 2014-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多