I first and foremost want to say that I am not super well versed with module integration and backend environments in general, which explains why this question may seem ridiculous.
I am currently trying to put together a basic website displaying scraped data within an HTML table using require.js and puppeteer. That said, I am running into issues when trying to load the webpage and can't seem to figure out how to fix it, even after consulting the require.js common error documentation for debugging.
Here is my current js script:
const puppeteer = require('puppeteer')
const fs = require('fs/promises')
async function start() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto("https://ciffc.net/en/ciffc/ext/member/sitrep/")
const names = await page.evaluate(() => {
return Array.from(document.querySelectorAll("#apl_table_wrapper td:nth-of-type(2)")).map(x => x.textContent)
})
await fs.writeFile("names.txt", names.join("\r\n"))
await browser.close()
}
start()
And here is the integration of the script within the head element of the HTML:
<head>
<title>Data Table</title>
<meta charSet="utf-8"/>
<link rel="stylesheet" href="style.css">
<script src="https://requirejs.org/docs/release/2.3.1/minified/require.js"></script>
<script src="index.js"></script>
</head>
Now when I load this html page, I run into this following error:
Uncaught Error: Module name "puppeteer" has not been loaded yet for context: _. Use require([])
I consulted the require.js documentation and found this specific error referenced within the "Common Errors" page, mentioning that this error occurs when there is a require('name') call, but the 'name' module has not been loaded yet. I then amended my code accordingly: which leads to an Uncaught SyntaxError: Identifier 'puppeteer' has already been declared:
require(['puppeteer', 'fs/promises'], function(puppeteer) {
const puppeteer = require('puppeteer')
const fs = require('fs/promises')
//rest of script
});
which leads to:
Uncaught SyntaxError: Identifier 'puppeteer' has already been declared
I have tried many different iterations of the script but have yet to be successful in getting it loaded correctly. How can I fix this issue?