jshemas / openGraphScraper

Node.js scraper service for Open Graph Info and More!
MIT License
642 stars 102 forks source link

Type check errors after upgrading to 6.6.0 #228

Open abrowne2 opened 1 week ago

abrowne2 commented 1 week ago

After upgrading to 6.6.0, noticed these failed:

node_modules/.pnpm/open-graph-scraper@6.6.0/node_modules/open-graph-scraper/index.ts(2,49): error TS2307: Cannot find module './lib/openGraphScraper' or its corresponding type declarations.
node_modules/.pnpm/open-graph-scraper@6.6.0/node_modules/open-graph-scraper/index.ts(6,8): error TS2307: Cannot find module './lib/types' or its corresponding type declarations.
src/lib/resolvers/queries/utils.ts(14,8): error TS2307: Cannot find module 'open-graph-scraper/dist/lib/types' or its corresponding type declarations.
jshemas commented 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.

jshemas commented 6 days ago

Can you try using open-graph-scraper@6.6.1.

frederichoule commented 4 days ago

Same problem here, using open-graph-scraper@6.6.1

jshemas commented 4 days ago

@frederichoule Cool. Can you give me a full example of the problem?

frederichoule commented 4 days ago

Just try to import ogs from 'open-graph-scraper'; into any TypeScript project and you'll get the error.

jshemas commented 4 days ago

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?

frederichoule commented 4 days ago

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"

frederichoule commented 4 days ago

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.

jshemas commented 3 days ago

@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'
}