我正在尝试在Node.JS中运行一个灯塔脚本(我是新手)。我遵循了这里的原始指令,https://github.com/GoogleChrome/lighthouse/blob/master/docs/readme.md#using-programmatically。我能够在包管理器控制台(Visual 2017)中完成前面的步骤:
npm install -g lighthouse
lighthouse https://airhorner.com/
//and
lighthouse https://airhorner.com/ --output=json --output-path=./report/test1.json但是,我确实收到了一个初步警告,即NPM只支持版本4到8的Node.JS,并推荐更新版本。问题是我正在运行Node v12和NPM v5 --这两个都是最新的。
当我创建如下脚本版本时(app.js)
const lighthouse = require('lighthouse');
const chromeLauncher = require('chrome-launcher');
const config = {
extends: 'lighthouse:default',
settings: {
emulatedFormFactor: 'desktop',
onlyCategories: 'performance',
output: 'json',
outputPath: './report.json'
}
};
function launchChromeAndRunLighthouse(url, opts = null, config) {
return chromeLauncher.launch().then(chrome => {
opts.port = chrome.port;
return lighthouse(url, opts, config).then(results => {
return chrome.kill().then(() => results.lhr);
});
});
}
// Usage:
launchChromeAndRunLighthouse('https://airhorner.com/', config).then(results => {
// Use results!
});并运行命令
C:\src\project> node app.js我发现错误-找不到“灯塔”模块
发布于 2019-10-28 19:32:20
不要在本地安装灯塔,在工作区域内使用它。首先,运行npm init,在当前工作dir中创建package.json文件
然后npm install --save lighthouse将下载它并将其保存到node_modules,现在您可以在工作dir中本地使用它了。
应该是这样的
然后运行node app.js
https://stackoverflow.com/questions/58596892
复制相似问题