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

标签 javascript node.js installation npm

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

相关文章:

javascript - asp mvc - 动态添加数据控件的最佳方式是什么

javascript - Node 脚本中 eval() 的替代方案

tomcat - Apache Syncope - 使用 Tomcat8.5.24 安装

javascript - jQuery 跳出位置?

javascript - 从 Bing Maps API 中的 URL 添加 PolygonOptions 到 GeoJSON

javascript - 如何根据特定区域设置对 JavaScript 中的字符串进行排序或比较?

javascript - GraphQL 解析器 - 在 promise 解决后返回我的函数

jquery - NW JS - 从 URL 下载并保存文件

Android 通过浏览器链接安装 APK

git - 为什么 git 安装在 AppData 而不是 Program Files 中?