我曾尝试浏览互联网并进行了大量研究,但我仍然对这个问题感到困惑。我正在尝试将使用puppeteer2.1.1的Node.js应用程序推送到Github中,以便随后可以在Azure上托管。尝试推送后出现这些错误。[尝试推送到git后出现错误消息]
[1:https://i.stack.imgur.com/BlShv.jpg
我尝试使用git lfs跟踪所有命令,然后跟踪文件,根据错误消息,我认为该文件必须为/.local-chromium。尝试再次推送后仍然失败。我已经尝试了2天,但仍然可以解决。是否有人使用过puppeteer并上传到GitHub遇到了同样的问题?我也对为什么它甚至转到node_modules文件夹感到困惑。我以为推送到git时会自动被忽略。这是下面的代码。
index.js
const puppeteer = require("puppeteer");
require('dotenv').config();
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
var schedule = require('node-schedule');
function coronaInfoSearch(){
puppeteer.launch({
headless:true
}).then(async browser =>{
//open new tab and go to specified url
const page = await browser.newPage();
await page.goto('https://www.worldometers.info/coronavirus/country/us/');
//select elements wanted
page.waitForSelector('td')
.then(async function(){
//var self explanatory
const njRowTotalCases =await page.$eval('table .even .sorting_1', element => element.innerHTML);
const njRowName = await page.$eval('table .even td', element => element.innerHTML);
const njRowActiveCases = await page.$eval('#usa_table_countries_today > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(6)', element => element.innerHTML);
const njRowDeaths = await page.$eval('#usa_table_countries_today > tbody:nth-child(2) > tr:nth-child(2) > td:nth-child(4)' , element => element.innerHTML);
var coronainfoOutput = "Total Cases:\n"+njRowTotalCases+"\n\n"+"Active Cases:"+njRowActiveCases+"\n\n"+"Total Deaths:"+njRowDeaths;
//atring to be sent for outputting
var coronainfoOutputHeading="NJ COVID-19 Update\n----------------\n";
//sent text message
client.messages
.create({
body: coronainfoOutputHeading + coronainfoOutput,
from: process.env.TWILIO_PHONE_NUMBER,
to: process.env.ANT_NUMBER
})
.then(message => console.log(message.sid));
})
});
};
schedule.scheduleJob("55 13 * * 0-6", function(){
coronaInfoSearch();
});
package.json
{
"name": "coronawebscrap",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dotenv": "^8.2.0",
"express": "^4.17.1",
"puppeteer": "^2.1.1",
"node-schedule": "^1.3.2",
"twilio": "^3.41.1"
}
}
。gitattributes
.local-chromium filter=lfs diff=lfs merge=lfs -text
node_modules/puppeteer/.local-chromium filter=lfs diff=lfs merge=lfs -text
编辑:将node_modules /放在.gitignore文件下,然后添加到git repo,然后提交,然后推送,我仍然遇到相同的错误。
。gitignore
.env
node_modules/
由于您不想上载node_modules,因此您需要在存储库的根目录中添加一个.gitignore
文件
看看:https://github.com/github/gitignore/blob/master/Node.gitignore