【问题标题】:How do I get html-snapshots to work?如何让 html-snapshots 工作?
【发布时间】:2013-12-17 20:57:56
【问题描述】:

我只是想运行html-snapshots。这应该很容易吧?

这是我开始的:

npm install html-snapshots

这就是我所需要的,对吧?这是我的 snapshots.js 文件:

var htmlSnapshots = require('html-snapshots');
htmlSnapshots.run({
    source: "sitemap.xml",
    hostname: "localhost",
    outputDir: "snapshots",
    outputDirClean: true,
    selector: "#results-widget"
});

然后运行它:

node snapshots.js

但是不:

module.js:340
    throw err;
          ^
Error: Cannot find module '.\robots'
    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.module.exports.create (C:\webdev\node_modules\html-snapshots\lib\input-generators\index.js:38:16)
    at Object.module.exports.run (C:\webdev\node_modules\html-snapshots\lib\html-snapshots.js:42:39)
    at Object.<anonymous> (C:\webdev\snapshots.js:2:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

wtf?

其他信息...

这是 html-snapshots.js 的一部分:

var inputFactory = require("./input-generators");
...
run: function(options, listener) {
    ...
    var inputGenerator = inputFactory.create(options.input);
    ...
    result = inputGenerator.run(options, (function(options, notifier){

另外,html-snapshots\lib\input-generators 文件夹包含文件robots.js

【问题讨论】:

  • 这个错误来自图书馆吗?也许它缺少一些依赖项。检查并查看inputGenerator 是什么,以及它是否是required
  • 谢谢@Houseman,你让我意识到安装机器人是错误的做法。 input-generators 文件夹中有一个 robots.js 由于某种原因没有被加载。 (不是说我已经解决了我的问题)
  • 如果你真的想感谢我,你可以点赞我的评论。 :)
  • @GilBirman,你用的是什么版本的html-snapshots?我已经检查了版本“0.2.1”并且引发错误var inputGenerator = inputFactory.create(options.input); 的语句在第 42 行(不是您的错误中的 43)。所以你可以使用旧版本或者html-snapshots\lib\html-snapshots.js已经修改。我建议从node_modules 中删除整个html-snapshots 目录,使用npm 再次下载并应用我提供的修复程序。您应该不会再遇到第二个错误。
  • 谢谢汤姆。这消除了错误。

标签: javascript node.js installation npm


【解决方案1】:

这看起来像是html-snapshots\lib\input-generators\index.js 文件中的问题 - 它在 Linux 系统上运行良好,但在 Windows 上失败(path.sep 已用于构建模块名称)

问题是它应该加载'./robots' 模块而不是'.\robots'

快速修复是更新 html-snapshots\lib\input-generators\index.js 文件 - 第 38 行。

换行:

result = require(file);

到:

result = require(path.join(__dirname, file));

它会正常工作。我希望这会有所帮助。

【讨论】:

  • 谢谢。现在出现新错误。我用底部的新错误更新了问题。
猜你喜欢
  • 2013-08-12
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 1970-01-01
  • 2020-02-04
  • 2015-03-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多