Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何让html快照工作?_Javascript_Node.js_Installation_Npm - Fatal编程技术网

Javascript 如何让html快照工作?

Javascript 如何让html快照工作?,javascript,node.js,installation,npm,Javascript,Node.js,Installation,Npm,我只是想跑。这应该很容易,对吧? 这是我开始的: npm install html-snapshots 这就是我所需要的,对吗?这是我的snapshots.js文件: var htmlSnapshots = require('html-snapshots'); htmlSnapshots.run({ source: "sitemap.xml", hostname: "localhost", outputDir: "snapshots", outputDirCle

我只是想跑。这应该很容易,对吧?

这是我开始的:

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)

另外,
html snapshots\lib\input generators
文件夹包含文件
robots.js
它看起来像是
html snapshots\lib\input generators\index.js
文件中的一个问题-它在Linux系统上工作正常,但在Windows上失败(
path.sep
已用于构建模块名)

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

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

换行:

致:


它会很好的工作。我希望这会有所帮助。

这个错误是来自图书馆吗?也许它缺少一些依赖项。检查并查看什么是
inputGenerator
,如果它是
所需的
“谢谢你@Houseman”,你让我意识到安装机器人是错误的。input generators文件夹中有一个robots.js由于某种原因未加载。(并不是说我已经解决了我的问题)如果你真的想感谢我,你可以对我的评论投赞成票@GilBirman,你使用什么版本的
html快照
?我已经检查了版本“0.2.1”和抛出错误的语句
var-inputGenerator=inputFactory.create(options.input)位于第42行(而不是错误中的43)。因此,您可以使用较旧的版本,或者
html snapshots\lib\html snapshots.js
已被修改。我建议从
node\u modules
中删除整个
html快照
目录,使用
npm
再次下载并应用我提供的修复程序。你不应该再犯第二个错误了。谢谢你,汤姆。这消除了错误。谢谢。现在出现新错误。我用底部的新错误更新了问题。
var inputFactory = require("./input-generators");
...
run: function(options, listener) {
    ...
    var inputGenerator = inputFactory.create(options.input);
    ...
    result = inputGenerator.run(options, (function(options, notifier){
result = require(file);
result = require(path.join(__dirname, file));