我只是想运行 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));
它会工作得很好。我希望这会有所帮助。
我是一名优秀的程序员,十分优秀!