I've been working on a web scraping project using axios, cheerio, and express. However, every time I attempt to run the project, it encounters errors.
For testing purposes, I am using a test page from my friend's website. Here is the code snippet I used:
const express = require('express')
const app = express()
const port = 3000
const publicDir = app.use(express.static('public'))
var cheerio = require('cheerio'); // A jQuery-like tool for node.js
const { replaceWith } = require('cheerio/lib/api/manipulation');
const axios = require('axios').default;
app.get('/', (req, res) => {
res.render('/public/index.html')
})
app.get('/imagineoranges', (req, res) => {
const $ = cheerio.load('/imagineoranges')
axios.get("https://imagineoranges.neocities.org")
.then(({data}) => res.send(data))
.then( $('a:link').css("color: white;") )
.then( $('a:visited').css("color: yellow;") )
.then( $('a:hover').css("color: yellow;") )
.then( $('body').css("@import url('https://fonts.googleapis.com/css2?family=Rubik&display=swap'); background-color: #ff7300; color: white; font-family: 'Rubik', sans-serif;") )
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
However, when you run this code, the following error occurs:
node:internal/modules/cjs/loader:535
throw e;
^
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/api/manipulation' is not defined by "exports" in /home/lucas/Desktop/UBlock/node_modules/cheerio/package.json
at new NodeError (node:internal/errors:393:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:292:9)
at packageExportsResolve (node:internal/modules/esm/resolve:602:3)
at resolveExports (node:internal/modules/cjs/loader:529:36)
at Module._findPath (node:internal/modules/cjs/loader:569:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:981:27)
at Module._load (node:internal/modules/cjs/loader:841:27)
at Module.require (node:internal/modules/cjs/loader:1061:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/home/lucas/Desktop/UBlock/index.js:6:25) {
code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
Node.js v19.0.1