Open abrowne2 opened 1 week ago
Hello, please follow the https://github.com/jshemas/openGraphScraper/blob/master/.github/ISSUE_TEMPLATE/bug_report.md template when opening a issue. I will need a full working example of the problem before I can debug this.
Can you try using open-graph-scraper@6.6.1
.
Same problem here, using open-graph-scraper@6.6.1
@frederichoule Cool. Can you give me a full example of the problem?
Just try to import ogs from 'open-graph-scraper';
into any TypeScript project and you'll get the error.
Let me trying asking it this way. Here is my code:
index.ts
import ogs from 'open-graph-scraper';
const options = { url: 'http://ogp.me/' };
ogs(options)
.then((data) => {
const { error, result } = data;
console.log('error:', error); // This returns true or false. True if there was an error. The error itself is inside the results object.
console.log('result:', result.ogImage); // This contains all of the Open Graph results
});
tsconfig.json
{
"include": [
"index.ts",
],
"compilerOptions": {
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2023"],
"module": "node16",
"moduleResolution": "node16",
"outDir": "./dist",
"skipLibCheck": true,
"strict": true,
"target": "es2022",
}
}
package.json
{
"name": "test-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"reinstall": "rm -rf node_modules && rm package-lock.json && npm i",
"run-script": "ts-node index"
},
"author": "",
"license": "ISC",
"dependencies": {
"open-graph-scraper": "6.6.1"
},
"devDependencies": {
"ts-node": "^10.9.1",
"typescript": "^5.4.5"
}
}
On node v18.18.0
... If I run npm run build
, I will get no build errors. If I run npm run run-script
, this is the output:
> ogs-test@1.0.0 run-script
> ts-node index
error: false
result: [
{
height: '300',
type: 'image/png',
url: 'https://ogp.me/logo.png',
width: '300',
alt: 'The Open Graph logo'
}
]
Can you response with your code?
Hey Josh, sorry I replied from my phone and I was in a hurry. Here is a sample repo with the bug https://github.com/frederichoule/sample-opengraphscraper - it's probably related to "target": "es2016", "module": "commonjs"
That being said, I'm using a kinda old boilerplate for Google Cloud Functions that I haven't updated in a while. I will update it right now to esnext and see if it works.
@frederichoule Hello, I was able to fix this in open-graph-scraper@6.6.2
.
https://github.com/frederichoule/sample-opengraphscraper should now work on this version. I updated the console.log
to console.log(data.result);
npm run start
> sample-opengraphscraper@1.0.0 start
> node dist/index.js
{
success: true,
ogSiteName: 'YouTube',
ogUrl: 'https://www.youtube.com/watch?v=9bZkp7q19f0',
ogTitle: 'PSY - GANGNAM STYLE(강남스타일) M/V',
ogDescription: "PSY - ‘I LUV IT’ M/V @ https://youtu.be/Xvjnoagk6GUPSY - ‘New Face’ M/V @https://youtu.be/OwJPPaEyqhIPSY - 8TH ALBUM '4X2=8' on iTunes @https://smarturl.it/P...",
alIosAppStoreId: '544007664',
alIosAppName: 'YouTube',
alIosUrl: 'vnd.youtube://www.youtube.com/watch?v=9bZkp7q19f0&feature=applinks',
alAndroidUrl: 'vnd.youtube://www.youtube.com/watch?v=9bZkp7q19f0&feature=applinks',
alWebUrl: 'http://www.youtube.com/watch?v=9bZkp7q19f0&feature=applinks',
ogType: 'video.other',
ogVideoSecureURL: 'https://www.youtube.com/embed/9bZkp7q19f0',
alAndroidAppName: 'YouTube',
alAndroidPackage: 'com.google.android.youtube',
ogVideoTag: 'Psy Gangnam Style',
fbAppId: '87741124305',
twitterCard: 'player',
twitterSite: '@youtube',
twitterUrl: 'https://www.youtube.com/watch?v=9bZkp7q19f0',
twitterTitle: 'PSY - GANGNAM STYLE(강남스타일) M/V',
twitterDescription: "PSY - ‘I LUV IT’ M/V @ https://youtu.be/Xvjnoagk6GUPSY - ‘New Face’ M/V @https://youtu.be/OwJPPaEyqhIPSY - 8TH ALBUM '4X2=8' on iTunes @https://smarturl.it/P...",
twitterAppNameiPhone: 'YouTube',
twitterAppIdiPhone: '544007664',
twitterAppNameiPad: 'YouTube',
twitterAppIdiPad: '544007664',
twitterAppUrliPhone: 'vnd.youtube://www.youtube.com/watch?v=9bZkp7q19f0&feature=applinks',
twitterAppUrliPad: 'vnd.youtube://www.youtube.com/watch?v=9bZkp7q19f0&feature=applinks',
twitterAppNameGooglePlay: 'YouTube',
twitterAppIdGooglePlay: 'com.google.android.youtube',
twitterAppUrlGooglePlay: 'https://www.youtube.com/watch?v=9bZkp7q19f0',
ogImage: [
{
height: '720',
url: 'https://i.ytimg.com/vi/9bZkp7q19f0/maxresdefault.jpg',
width: '1280',
type: 'jpg'
}
],
ogVideo: [
{
height: '720',
type: 'text/html',
url: 'https://www.youtube.com/embed/9bZkp7q19f0',
width: '1280'
}
],
twitterImage: [ { url: 'https://i.ytimg.com/vi/9bZkp7q19f0/maxresdefault.jpg' } ],
twitterPlayer: [
{
height: '720',
url: 'https://www.youtube.com/embed/9bZkp7q19f0',
width: '1280'
}
],
ogLocale: 'en',
ogDate: '2012-07-15T00:46:32-07:00',
favicon: 'https://www.youtube.com/s/desktop/28bb7000/img/favicon.ico',
charset: 'UTF-8',
jsonLD: [
{
'@context': 'http://schema.org',
'@type': 'BreadcrumbList',
itemListElement: [Array]
}
],
requestUrl: 'https://www.youtube.com/watch?v=9bZkp7q19f0'
}
After upgrading to 6.6.0, noticed these failed: