【问题标题】:grunt fails, "cannot find module 'tmp'"咕噜声失败,“找不到模块'tmp'”
【发布时间】:2014-10-17 21:00:30
【问题描述】:

我正在接管一个现有项目。它包含一个 package.json 和 Gruntfile。根据here的指示我已经跑了

npm install

在全局安装 grunt-cli 之后。

但是,运行 grunt 会导致

$ grunt --env=production
Loading "compass.js" tasks...ERROR
>> Error: Cannot find module 'tmp'
Warning: Task "compass" not found. Use --force to continue.

Aborted due to warnings.

使用 -v 运行会给出回溯:

Loading "compass.js" tasks...ERROR
>> Error: Cannot find module 'tmp'
>>     at Function.Module._resolveFilename (module.js:338:15)
>>     at Function.Module._load (module.js:280:25)
>>     at Module.require (module.js:364:17)
>>     at require (module.js:380:17)
>>     at Object.exports.init (/..(path)../node_modules/grunt-contrib-compass/tasks/lib/compass.js:4:13)
>>     at Object.module.exports (/..(path)../node_modules/grunt-contrib-compass/tasks/compass.js:12:42)
>>     at loadTask (/..(path)../node_modules/grunt/lib/grunt/task.js:325:10)
>>     at /..(path)../node_modules/grunt/lib/grunt/task.js:361:7
>>     at Array.forEach (native)
>>     at loadTasks (/..(path)../node_modules/grunt/lib/grunt/task.js:360:11)

"..(path).." 已经被我插入替换了一个长的基本路径,它是项目的根目录。

经过进一步调查,compass.js 导入了 'tmp' 模块

  var tmp = require('tmp');

谁/什么提供这个模块?

【问题讨论】:

  • Gruntfile 中有什么?
  • 太多了,440 行代码,我怀疑问题实际上出在 compass.js 的“tmp”导入上,请参阅更新。

标签: gruntjs npm


【解决方案1】:

删除 node_modules(令我惊讶的是它在源代码控制下)并运行

npm cache clean
npm install

解决了这个问题。

【讨论】:

    【解决方案2】:

    从 npm@5 开始,npm 缓存可以从损坏问题中自我修复,并且从缓存中提取的数据保证有效。如果您想确保一切一致,请改用npm cache verify

    如果你想强制清理,请尝试npm cache clean --force,然后运行npm cache verify

    【讨论】:

      猜你喜欢
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2013-03-15
      • 1970-01-01
      • 2015-05-25
      • 2015-08-03
      相关资源
      最近更新 更多