gpt4 book ai didi

javascript - 如何让 html 快照发挥作用?

转载 作者:太空宇宙 更新时间:2023-11-04 01:08:20 25 4
gpt4 key购买 nike

我只是想运行 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)

什么鬼?

其他信息...

这是 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

最佳答案

这看起来像是 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));

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

关于javascript - 如何让 html 快照发挥作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20644517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com